"""A complete DyUI app that shows the `form` component.

Save it as app.py, then run:  dyui run app.py
"""
import dyui
from dyui import ui

app = dyui.App(title="Form demo", starters=["Show me"], persist=False)


@app.on_message
async def reply(msg: dyui.Message, chat: dyui.Chat):
    yield "Here is the `form` component."
    yield ui.Form(ui.Field("name"), ui.Field("email", type="email"), title="Contact", action="contact")


@app.on_action("contact")
async def on_contact(action: dyui.Action, chat: dyui.Chat):
    # action.values holds what the user entered or chose; action.data is the static data
    yield f"Got `{action.name}` from **{action.label}** with values `{action.values}`."


@app.on_action("form_submit")
async def on_form_submit(action: dyui.Action, chat: dyui.Chat):
    # action.values holds what the user entered or chose; action.data is the static data
    yield f"Got `{action.name}` from **{action.label}** with values `{action.values}`."
