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_after(data) -> go.Figure:
    fig = _sprint_completion_chart(data)
    for index in (2, 4):
        sprint, count = data[index]
        fig.add_annotation(
            x=sprint,
            y=count,
            text=f"{count} tickets",
            ax=0,
            ay=-32,
            arrowhead=0,
            arrowwidth=1,
            arrowcolor="#64748b",
            standoff=5,
        )
    return fig


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