import plotly.graph_objects as go


def load_data():
    """Return illustrative daily ticket counts for two service desks."""
    return [
        (1, 22, 28),
        (2, 26, 32),
        (3, 30, 35),
        (4, 40, 44),
        (5, 46, 42),
        (6, 48, 40),
        (7, 52, 43),
        (8, 55, 44),
    ]


def value_table(data):
    """Return both service desks' resolved ticket counts by day."""
    return {
        "columns": ["Day", "North desk", "South desk"],
        "rows": [list(row) for row in data],
    }


def _ticket_chart(data) -> go.Figure:
    days, north, south = zip(*data, strict=True)
    fig = go.Figure()
    for name, counts, color in (
        ("North desk", north, "#245785"),
        ("South desk", south, "#9c4221"),
    ):
        fig.add_scatter(x=days, y=counts, name=name, mode="lines+markers", line_color=color)
    fig.update_layout(
        template="simple_white",
        font={"family": "Inter, system-ui, -apple-system, sans-serif", "color": "#1f2937"},
        title={"text": "Tickets resolved by service desk", "x": 0, "xanchor": "left"},
        xaxis={"title": "Day", "tickvals": days, "range": [0.75, 8.25]},
        yaxis={"title": "Tickets resolved", "range": [20, 60]},
        margin={"l": 72, "r": 96, "t": 56, "b": 60},
    )
    return fig


def make_before(data) -> go.Figure:
    """Put the opaque legend over the lines where the desks change places."""
    fig = _ticket_chart(data)
    fig.update_layout(
        legend={"x": 0.45, "y": 0.55, "xanchor": "left", "yanchor": "middle", "bgcolor": "#ffffff"}
    )
    return fig


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