import plotly.graph_objects as go


import plotly.io as pio


from plotly.subplots import make_subplots


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,
        },
    )
)


MONTHS = ["Jan", "Feb", "Mar", "Apr", "May", "Jun"]


def load_data():
    return {"Harbor": [81, 83, 82, 85, 86, 88], "Hill": [94, 95, 96, 95, 97, 98]}


def make_before(data):
    fig = make_subplots(rows=2, cols=1, vertical_spacing=0.2)
    for row, (depot, scores) in enumerate(data.items(), 1):
        fig.add_scatter(x=MONTHS, y=scores, mode="lines+markers", name=depot, row=row, col=1)
        fig.update_yaxes(
            range=[min(scores) - 1, max(scores) + 1], title_text="On time (%)", row=row, col=1
        )
    fig.update_layout(height=1050, title_text="EXCLUDES CANCELLED RUNS", margin={"t": 65})
    return fig


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