import plotly.graph_objects as go


def load_data():
    return [
        (1, 22),
        (2, 24),
        (3, 25),
        (4, 26),
        (20, 29),
        (21, 31),
        (22, 32),
        (23, 33),
    ]


def value_table(data):
    return {
        "columns": ["Elapsed day", "Completed work orders"],
        "rows": [list(row) for row in data],
    }


def work_orders_figure():
    fig = go.Figure()
    fig.update_layout(
        template="simple_white",
        font={"family": "Inter, system-ui, -apple-system, sans-serif", "color": "#1f2937"},
        title="Completed work orders by day",
        xaxis_title="Elapsed day",
        yaxis={"title": "Completed work orders", "range": [19, 36]},
        margin={"l": 84, "r": 24, "t": 56, "b": 60},
        showlegend=False,
    )
    return fig


def make_after(data) -> go.Figure:
    fig = work_orders_figure()
    for period in (data[:4], data[4:]):
        days, completed = zip(*period, strict=True)
        fig.add_scatter(
            x=days,
            y=completed,
            mode="lines+markers",
            line_color="#356890",
            hovertemplate="Day %{x}: %{y}<extra></extra>",
        )
    fig.update_xaxes(range=[0, 24], tickvals=[1, 4, 8, 12, 16, 20, 23])
    fig.add_annotation(x=12, y=27, text="No records for days 5 to 19", showarrow=False)
    return fig


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