import plotly.graph_objects as go


def load_data():
    return [
        ("Jan", 400, 440),
        ("Feb", 500, 475),
        ("Mar", 600, 660),
        ("Apr", 500, 600),
        ("May", 400, 420),
        ("Jun", 600, 540),
    ]


def value_table(data):
    return {
        "columns": ["Month", "Calls in 2025", "Calls in 2026"],
        "rows": [list(row) for row in data],
    }


def _call_volume_change_chart(data) -> go.Figure:
    months, prior_calls, current_calls = zip(*data, strict=True)
    changes = [
        (current - prior) / prior for prior, current in zip(prior_calls, current_calls, strict=True)
    ]
    fig = go.Figure(
        go.Bar(
            x=months,
            y=changes,
            marker_color="#246487",
            hovertemplate="%{x}: %{y:+.0%}<extra></extra>",
        )
    )
    fig.update_layout(
        template="simple_white",
        font={"family": "Inter, system-ui, -apple-system, sans-serif", "color": "#1f2937"},
        title={"text": "Help desk call volume", "x": 0.08},
        yaxis={"title": "Change in calls", "tickformat": ".0%", "range": [-0.15, 0.25]},
        margin={"l": 76, "r": 28, "t": 84, "b": 48},
    )
    return fig


def make_after(data) -> go.Figure:
    fig = _call_volume_change_chart(data)
    fig.update_layout(title_subtitle_text="Each month in 2026 compared with the same month in 2025")
    fig.update_yaxes(title_text="Change from 2025")
    return fig


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