import plotly.graph_objects as go


import plotly.io as pio


INK = "#1C1917"


MUTED = "#57534E"


WARM_EDITORIAL_PALETTE = [
    "#0F766E",
    "#C2410C",
    "#1D4ED8",
    "#A16207",
    "#7E22CE",
    "#475569",
    "#0369A1",
    "#1C1917",
]


CANVAS = "#FFF7ED"


RULE = "#E7DDD2"


pio.templates["warm_editorial"] = go.layout.Template(
    layout=go.Layout(
        colorway=WARM_EDITORIAL_PALETTE,
        font={"family": "Inter, system-ui, -apple-system, sans-serif", "size": 13, "color": INK},
        title={
            "x": 0,
            "xanchor": "left",
            "font": {"family": "Georgia, 'Times New Roman', serif", "size": 18, "color": INK},
        },
        paper_bgcolor=CANVAS,
        plot_bgcolor=CANVAS,
        xaxis={
            "showgrid": False,
            "showline": True,
            "linecolor": "#A8A29E",
            "tickcolor": "#A8A29E",
            "tickfont": {"color": MUTED},
            "automargin": True,
        },
        yaxis={
            "showgrid": True,
            "gridcolor": RULE,
            "gridwidth": 1,
            "showline": False,
            "tickcolor": "#A8A29E",
            "tickfont": {"color": MUTED},
            "zeroline": False,
            "automargin": True,
        },
    )
)


def load_data():
    return [
        ("2026-05-01", 6, 8),
        ("2026-06-15", 7, 9),
        ("2026-07-01", 8, 10),
        ("2026-08-15", 7, 9),
        ("2026-09-01", 6, 8),
    ]


def admission_rates(data):
    dates, weekday, weekend = zip(*data, strict=True)
    fig = go.Figure()
    for name, rates, dash in (("Weekday", weekday, "solid"), ("Weekend", weekend, "dash")):
        fig.add_scatter(x=dates, y=rates, mode="lines", name=name, line_dash=dash)
    return fig


def make_before(data):
    fig = admission_rates(data)
    fig.update_layout(
        template="plotly",
        title="Pool admission",
        xaxis_title="Effective date",
        yaxis_title="Admission (dollars)",
        yaxis_range=[0, 45],
        showlegend=True,
        legend={"x": 0.1, "y": 0.24, "yanchor": "top"},
    )
    fig.update_xaxes(showline=True, mirror=True, linecolor="#59677C", tickfont_size=8)
    fig.update_yaxes(showline=True, mirror=True, linecolor="#59677C", tickfont_size=8)
    return fig


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