import plotly.graph_objects as go


def load_data():
    return [
        ("Jan", 18),
        ("Feb", 16),
        ("Mar", 17),
        ("Apr", 14),
        ("May", 13),
        ("Jun", 12),
    ]


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


def _appointment_wait_chart(data) -> go.Figure:
    periods, values = zip(*data, strict=True)
    fig = go.Figure(
        go.Scatter(x=periods, y=values, mode="lines+markers", line={"color": "#246487"})
    )
    fig.update_layout(
        template="simple_white",
        font={"family": "Inter, system-ui, -apple-system, sans-serif", "color": "#1f2937"},
        title={"text": "Clinic appointment wait", "x": 0.08},
        xaxis={"title": "Month", "tickmode": "array", "tickvals": list(periods), "tickangle": 0},
        yaxis_title="Median wait (minutes)",
        margin={"l": 68, "r": 28, "t": 80, "b": 65},
    )
    return fig


def make_before(data) -> go.Figure:
    fig = _appointment_wait_chart(data)
    fig.update_layout(
        title_text="Month-by-month reporting of the median number of minutes<br>"
        "spent waiting for a scheduled appointment at the clinic",
        margin_t=106,
    )
    fig.update_xaxes(title_text="Month in which the appointment was scheduled to take place")
    fig.update_yaxes(title_text="Median number of minutes spent waiting")
    return fig


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