import plotly.graph_objects as go


FONT = {"family": "Inter, system-ui, -apple-system, sans-serif", "color": "#1f2937"}


def load_data():
    return [
        ("Canal", "2026-07-02", "2026-07-05"),
        ("Cedar", "2026-07-02", "2026-07-11"),
        ("Harbor", "2026-07-04", "2026-07-08"),
        ("Ridge", "2026-07-08", None),
        ("South", "2026-07-10", "2026-07-15"),
    ]


def value_table(data):
    return {
        "columns": ["Site", "Closed from", "Reopened on"],
        "rows": [list(row) for row in data],
    }


def _closure_layout(fig):
    fig.update_layout(
        template="simple_white",
        font=FONT,
        title="Footpath closures during July maintenance",
        showlegend=False,
        xaxis={
            "type": "date",
            "range": ["2026-07-01", "2026-07-21"],
            "tick0": "2026-07-02",
            "dtick": 345600000,
            "tickformat": "%b %d",
        },
        yaxis={
            "autorange": "reversed",
            "categoryorder": "array",
            "categoryarray": ["Canal", "Cedar", "Harbor", "Ridge", "South"],
        },
        margin={"l": 77, "r": 26, "t": 58, "b": 52},
    )
    return fig


def make_after(data) -> go.Figure:
    fig = go.Figure()
    cutoff = "2026-07-16"
    for site, start, end in data:
        fig.add_scatter(
            x=[start, end or cutoff],
            y=[site, site],
            mode="lines+markers",
            marker={"symbol": ["circle", "circle" if end else "triangle-right"], "size": [7, 9]},
            line={"color": "#24688c", "width": 3},
            hoverinfo="skip",
        )
        if end is None:
            fig.add_annotation(
                x=cutoff, y=site, xshift=10, xanchor="left", text="Still closed", showarrow=False
            )
    return _closure_layout(fig)


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