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:
    from plotly.subplots import make_subplots

    fig = make_subplots(rows=1, cols=2, shared_yaxes=True, subplot_titles=("Lunch", "Dinner"))
    for column, meal in enumerate(("Lunch", "Dinner"), start=1):
        days, bills = zip(*((day, count) for day, time, count in data if time == meal), strict=True)
        fig.add_trace(go.Bar(x=days, y=bills, showlegend=False), row=1, col=column)
    fig.update_layout(template="simple_white")
    fig.update_yaxes(range=[0, 100], dtick=20, showgrid=True, gridcolor="#e8e8e8", gridwidth=1)
    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())
