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

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

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


@app.on_message
async def reply(msg: dyui.Message, chat: dyui.Chat):
    yield "Here is the `buttons` component."
    yield ui.Buttons(ui.Button("Approve", action="approve", style="primary"), ui.Button("Reject", action="reject"))


@app.on_action("approve")
async def on_approve(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("reject")
async def on_reject(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}`."
