import plotly.graph_objects as go


FONT = {"family": "Inter, system-ui, -apple-system, sans-serif", "color": "#1f2937"}


def load_data():
    return [
        ("Jan", 84, 78, 10),
        ("Feb", 92, 83, 12),
        ("Mar", 86, 91, 11),
        ("Apr", 105, 89, 16),
        ("May", 97, 102, 14),
        ("Jun", 89, 98, 9),
    ]


def value_table(data):
    return {
        "columns": ["Month", "Tickets opened", "Tickets closed", "Median wait (hours)"],
        "rows": [list(row) for row in data],
    }


def _support_traces(data, wait_axis):
    months, opened, closed, wait = zip(*data, strict=True)
    fig = go.Figure()
    fig.add_scatter(
        x=months, y=opened, name="Opened", mode="lines+markers", line={"color": "#24688c"}
    )
    fig.add_scatter(
        x=months, y=closed, name="Closed", mode="lines+markers", line={"color": "#8a4c22"}
    )
    fig.add_scatter(
        x=months,
        y=wait,
        yaxis=wait_axis,
        name="Median wait",
        mode="lines+markers",
        line={"color": "#596779"},
    )
    return fig


def make_before(data) -> go.Figure:
    fig = _support_traces(data, "y2")
    fig.update_layout(
        template="simple_white",
        font=FONT,
        title="Support desk activity and response time",
        yaxis={"title": "Tickets", "range": [70, 110]},
        yaxis2={
            "title": "Median wait (hours)",
            "overlaying": "y",
            "side": "right",
            "range": [7, 17],
        },
        legend={"orientation": "h", "y": 1.02},
        margin={"l": 65, "r": 80, "t": 88, "b": 45},
    )
    return fig


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