"""
streamlit_app.py — a rapid-PoC chat UI over the banking assistant.

    pip install -r requirements.txt
    streamlit run streamlit_app.py

This is the JD's "Streamlit for rapid PoC development" — a few lines of UI over
the tested chat_logic layer. Note the HUMAN-APPROVAL buttons that appear for a
transfer: the UI surfaces the same human-in-the-loop gate the agent enforces.
"""
from __future__ import annotations

import streamlit as st

from chat_logic import ChatSession

st.set_page_config(page_title="Bank Assistant (PoC)", page_icon="🏦")
st.title("🏦 Banking Assistant — PoC")
st.caption("Grounded answers · live data via tools · human-approved transfers · Arabic/English")

if "session" not in st.session_state:
    st.session_state.session = ChatSession()
sess: ChatSession = st.session_state.session

# Render history.
for role, text in sess.history:
    with st.chat_message(role):
        st.write(text)

# Approval buttons when a transfer is pending.
if sess.awaiting_approval:
    st.warning("A transfer needs your approval.")
    c1, c2 = st.columns(2)
    if c1.button("✅ Approve"):
        sess.approve(True)
        st.rerun()
    if c2.button("❌ Decline"):
        sess.approve(False)
        st.rerun()
else:
    if prompt := st.chat_input("Ask about your account, policies, or request a transfer…"):
        sess.send(prompt)
        st.rerun()

with st.sidebar:
    st.subheader("Try")
    st.code("How long to dispute a transaction?\n"
            "What's my balance?\n"
            "transfer 100 to AE_friend\n"
            "ما هي رسوم الحساب الجاري؟\n"
            "Should I invest in stocks?")
    st.caption("Backed by the Lab 07 capstone (offline). Swap in Azure providers to go live.")
