import streamlit as st
from utils import api

def show() -> None:
    st.subheader("Clerk View: Transaction Entry & Log")

    with st.form("tx_form", clear_on_submit=True):
        sku = st.text_input("SKU", placeholder="e.g., SKU-12345")
        qty = st.number_input("Quantity", min_value=1, step=1)
        ttype = st.selectbox("Type", ["receive", "ship", "transfer"])
        warehouse = st.text_input("Warehouse ID", placeholder="e.g., 1")
        submitted = st.form_submit_button("Submit transaction")

    if submitted:
        payload = {"sku": sku, "qty": int(qty), "type": ttype, "warehouse": warehouse}
        res = api.post_transaction(payload)
        if res.get("accepted", False):
            st.success("Transaction recorded ✅ (mock if API not available)")
        else:
            st.error("Failed to record transaction. Please try again.")

    st.markdown("### 📜 Recent transactions")
    st.info("Waiting for Transactions API (US3). This list will auto-populate when it’s live.")

show()  
