import plotly.graph_objects as go


def load_data():
    return [
        ("1", 17),
        ("2", 20),
        ("3", 25),
        ("4", 23),
        ("5", 27),
        ("6", 22),
    ]


def value_table(data):
    return {
        "columns": ["Sprint", "Completed tickets"],
        "rows": [list(row) for row in data],
    }


def _sprint_completion_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": "Completed support tickets", "x": 0.08},
        xaxis={"title": "Sprint", "tickmode": "array", "tickvals": list(periods), "tickangle": 0},
        yaxis_title="Completed tickets",
        margin={"l": 68, "r": 28, "t": 80, "b": 65},
    )
    fig.update_yaxes(range=[15, 33])
    return fig


def make_before(data) -> go.Figure:
    fig = _sprint_completion_chart(data)
    fig.add_annotation(x="4", y=30, text="25 tickets", showarrow=False)
    fig.add_annotation(x="6", y=30, text="27 tickets", showarrow=False)
    return fig


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