"""Job Tracker — built with zuzu.

Demonstrates: Relations (3 tables), Choice colors, Rating, computed fields,
group_by, visibility, inline actions (cycle status).
"""

import zuzu

companies = zuzu.record("Companies",
    name="",
    industry="",
    size=zuzu.Choice(["startup", "mid-size", "enterprise"], colors={
        "startup": "green",
        "mid-size": "blue",
        "enterprise": "purple",
    }),
    website="",
    notes="",
)

applications = zuzu.record("Applications",
    company=companies,
    role="",
    status=zuzu.Choice(["applied", "screening", "interview", "offer", "rejected", "withdrawn"], colors={
        "applied": "blue",
        "screening": "purple",
        "interview": "yellow",
        "offer": "green",
        "rejected": "red",
        "withdrawn": "orange",
    }),
    salary_range="",
    applied_date=zuzu.date,
    excitement=zuzu.Rating(0, max=5),
    notes="",
    # Computed: days since applied
    active=lambda r: r.get("status", "") in ("applied", "screening", "interview"),
)

contacts = zuzu.record("Contacts",
    company=companies,
    name="",
    role="",
    email="",
    linkedin="",
    notes="",
)

app = zuzu.app("Job Tracker", records=[companies, applications, contacts])

# Customize lists
app.page("Companies").show(title="name", subtitle="industry", badge="size")
app.page("Applications").show(title="role", subtitle="salary_range", badge="status", group_by="status")
app.page("Contacts").show(title="name", subtitle="role", badge="company")

# Dashboard
with zuzu.page("Dashboard"):
    total = applications.count()
    in_progress = applications.where(applications.status.is_in(["screening", "interview"])).count()
    offers = applications.where(applications.status == "offer").count()
    rejected = applications.where(applications.status == "rejected").count()

    zuzu.metric("Total Applied", total)
    zuzu.metric("In Progress", in_progress)
    zuzu.metric("Offers", offers)
    zuzu.metric("Rejected", rejected)

    zuzu.chart(applications, x="status", y="role", aggregate="count", kind="bar")

    zuzu.section("Hot Leads")
    zuzu.list(
        applications.where(
            (applications.status.is_in(["screening", "interview"])) &
            (applications.excitement > 3)
        ).sort("excitement", descending=True),
        title="role",
        subtitle="salary_range",
        badge="status",
        empty="No hot leads right now.",
        visible=in_progress > 0,
    )

    zuzu.section("Companies")
    zuzu.metric("Total Companies", companies.count())
    zuzu.metric("Contacts", contacts.count())

app.run()
