"""Expense Tracker — built with zuzu.

Demonstrates: Currency type, Choice with colors, group_by, computed fields, visibility.
"""

import zuzu

expenses = zuzu.record("Expenses",
    description="",
    amount=zuzu.Currency(0.0, symbol="$"),
    category=zuzu.Choice(["food", "transport", "entertainment", "bills", "subscriptions", "other"], colors={
        "food": "green",
        "transport": "blue",
        "entertainment": "purple",
        "bills": "red",
        "subscriptions": "yellow",
        "other": "orange",
    }),
    date=zuzu.date,
    recurring=False,
)

app = zuzu.app("Expense Tracker", records=[expenses])

# Group expenses by category in the list
app.page("Expenses").show(
    title="description",
    subtitle="amount",
    badge="category",
    group_by="category",
)

# Dashboard with conditional visibility
with zuzu.page("Summary"):
    total = expenses.total("amount")
    count = expenses.count()

    zuzu.metric("Total Spent", total)
    zuzu.metric("Transactions", count)
    zuzu.metric("Average", expenses.average("amount"), visible=count > 0)

    zuzu.chart(expenses, x="category", y="amount", aggregate="sum", kind="bar")

    zuzu.section("Top 5 Expenses")
    zuzu.list(expenses.sort("amount", descending=True).first(5),
        title="description",
        subtitle="amount",
        badge="category",
    )

app.run()
