import plotly.graph_objects as go


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


def load_data():
    return [
        ("Canal", 72, 67),
        ("Cedar", 59, 81),
        ("Harbor", 76, 74),
        ("Ridge", 84, 86),
        ("South", 65, 62),
    ]


def value_table(data):
    return {
        "columns": ["Site", "Spring score", "Autumn score"],
        "rows": [list(row) for row in data],
    }


def _site_scores(data, *, connect_sites):
    fig = go.Figure()
    seasons = ["Spring", "Autumn"]
    for site, spring, autumn in data:
        focus = connect_sites and site == "Cedar"
        color = "#1d608a" if focus else "#8191a0"
        fig.add_scatter(
            x=seasons,
            y=[spring, autumn],
            mode="lines+markers" if connect_sites else "markers",
            marker={"color": color, "size": 9},
            line={"color": color, "width": 3 if focus else 1.5},
            meta=site,
            hovertemplate="%{meta}, %{x}: %{y} points<extra></extra>",
        )
        if connect_sites:
            fig.add_annotation(
                x="Autumn",
                y=autumn,
                text=site,
                xshift=9,
                xanchor="left",
                showarrow=False,
                font={"color": "#1d608a" if focus else "#364554"},
            )
    fig.update_layout(
        template="simple_white",
        font=FONT,
        showlegend=False,
        title="Trail condition scores by season",
        xaxis={"type": "category", "range": [-0.3, 1.45]},
        yaxis={"title": "Condition score (points)", "range": [55, 90], "dtick": 5},
        margin={"l": 86, "r": 22, "t": 60, "b": 56},
    )
    return fig


def make_before(data) -> go.Figure:
    return _site_scores(data, connect_sites=False)


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