import plotly.express as px


import plotly.graph_objects as go


def load_data():
    tips = px.data.tips()
    days = ("Thur", "Fri", "Sat", "Sun")
    return [
        (day, meal, int(((tips["day"] == day) & (tips["time"] == meal)).sum()))
        for day in days
        for meal in ("Lunch", "Dinner")
    ]


def value_table(data):
    return {"columns": ["Day", "Meal", "Bills"], "rows": [list(row) for row in data]}


def make_after(data) -> go.Figure:
    fig = go.Figure()
    for meal, color in (("Lunch", "#245a80"), ("Dinner", "#b98442")):
        days, counts = zip(
            *((day, count) for day, time, count in data if time == meal), strict=True
        )
        fig.add_trace(
            go.Bar(
                x=days,
                y=counts,
                name=meal,
                marker_color=color,
                text=[f"{meal} {count}" if count >= 10 else "" for count in counts],
                textposition="outside",
            )
        )
    fig.update_layout(
        template="simple_white", barmode="group", yaxis_title="Bills", yaxis_range=[0, 105]
    )
    fig.update_layout(
        font={"family": "Inter, system-ui, -apple-system, sans-serif", "color": "#1f2937"},
        colorway=["#3b82c4", "#d97706", "#14967f", "#8b5cf6", "#dc4c3e", "#78716c"],
    )
    return fig


if __name__ == "__main__":
    print(make_after(load_data()).to_json())
