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_before(data) -> go.Figure:
    days, completed = zip(*data, strict=True)
    positions = list(range(len(data)))
    fig = work_orders_figure()
    fig.add_scatter(
        x=positions,
        y=completed,
        mode="lines+markers",
        line_color="#356890",
        customdata=days,
        hovertemplate="Day %{customdata}: %{y}<extra></extra>",
    )
    fig.update_xaxes(tickvals=positions, ticktext=days)
    return fig


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