import plotly.graph_objects as go


def load_data():
    return [
        (1, 10),
        (2, 12),
        (3, 15),
        (4, 20),
        (5, 18),
        (6, 16),
    ]


def value_table(data):
    return {"columns": ["Day", "Water temperature (°C)"], "rows": [list(row) for row in data]}


def water_temperature_figure(data, fahrenheit_tick_positions):
    days, temperatures = zip(*data, strict=True)
    fig = go.Figure(
        go.Scatter(
            x=temperatures,
            y=days,
            mode="markers",
            marker={"color": "#356890", "size": 9},
            hovertemplate="Day %{y}: %{x} °C<extra></extra>",
        )
    )
    fig.add_scatter(x=temperatures, y=days, xaxis="x2", mode="markers", opacity=0, hoverinfo="skip")
    fig.update_layout(
        template="simple_white",
        font={"family": "Inter, system-ui, -apple-system, sans-serif", "color": "#1f2937"},
        title="Daily water temperature",
        xaxis={"title": "Temperature (°C)", "range": [0, 30], "dtick": 5},
        yaxis={"title": "Day", "tickvals": days, "range": [6.5, 0.5]},
        xaxis2={
            "title": "Temperature (°F)",
            "overlaying": "x",
            "side": "top",
            "matches": "x",
            "tickvals": fahrenheit_tick_positions,
            "ticktext": ["32", "41", "50", "59", "68", "77", "86"],
            "showgrid": False,
        },
        showlegend=False,
        margin={"l": 64, "r": 32, "t": 104, "b": 60},
    )
    return fig


def make_before(data) -> go.Figure:
    return water_temperature_figure(data, [0, 4, 8, 12, 16, 20, 24])


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