import plotly.graph_objects as go


def load_data():
    return [
        ("Intake", 0, 0),
        ("Sorting", 10, 0),
        ("Cooling", 10, 20),
        ("Inspection", 35, 20),
        ("Shipping", 35, 5),
    ]


def value_table(data):
    return {
        "columns": ["Checkpoint", "East offset (m)", "North offset (m)"],
        "rows": [list(row) for row in data],
    }


def checkpoint_route(data, east, north):
    names = [name for name, _, _ in data]
    fig = go.Figure(
        go.Scatter(
            x=east,
            y=north,
            mode="lines+markers+text",
            text=names,
            textposition="top center",
            line_color="#356890",
            hovertemplate="%{text}: %{x} m east, %{y} m north<extra></extra>",
        )
    )
    fig.update_layout(
        template="simple_white",
        font={"family": "Inter, system-ui, -apple-system, sans-serif", "color": "#1f2937"},
        title="Warehouse route between checkpoints",
        xaxis={"title": "East offset (m)", "range": [-7, 42], "dtick": 10},
        yaxis={"title": "North offset (m)", "range": [-5, 29], "dtick": 5},
        height=430,
        margin={"l": 76, "r": 24, "t": 56, "b": 60},
    )
    return fig


def make_before(data) -> go.Figure:
    fig = checkpoint_route(data, [0, 8, 16, 24, 32], [0, 0, 0, 0, 0])
    fig.update_yaxes(scaleanchor="x", scaleratio=1, constrain="domain")
    fig.update_xaxes(constrain="domain")
    return fig


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