import plotly.graph_objects as go


def load_data():
    return [
        ("Jan", 82, 65, 37),
        ("Feb", 88, 61, 39),
        ("Mar", 94, 67, 40),
        ("Apr", 90, 64, 42),
        ("May", 102, 62, 43),
        ("Jun", 110, 60, 45),
    ]


def value_table(data):
    return {
        "columns": ["Month", "Web bookings", "Phone bookings", "Desk bookings"],
        "rows": [list(row) for row in data],
    }


def _booking_channel_chart(data) -> go.Figure:
    months, web, phone, desk = zip(*data, strict=True)
    fig = go.Figure()
    channels = (
        ("Web", web, "#246487"),
        ("Phone", phone, "#95551c"),
        ("Desk", desk, "#39735e"),
    )
    for name, counts, color in channels:
        fig.add_trace(go.Bar(x=months, y=counts, name=name, marker_color=color))
    fig.update_layout(
        template="simple_white",
        font={"family": "Inter, system-ui, -apple-system, sans-serif", "color": "#1f2937"},
        title={"text": "Museum bookings by channel", "x": 0.08},
        barmode="group",
        xaxis_tickangle=0,
        yaxis={"title": "Bookings", "range": [0, 120]},
        margin={"l": 64, "r": 30, "t": 112, "b": 50},
    )
    return fig


def make_after(data) -> go.Figure:
    fig = _booking_channel_chart(data)
    fig.update_layout(
        legend={
            "orientation": "h",
            "x": 0,
            "y": 1.02,
            "xanchor": "left",
            "yanchor": "bottom",
            "traceorder": "normal",
            "font": {"size": 13},
        }
    )
    return fig


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