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


WEEKS = ["W1", "W2", "W3", "W4"]


def load_data():
    return {
        "Harbor": [[12, 14, 15, 16], [15, 17, 20, 24]],
        "Hill": [[12, 13, 12, 14], [13, 13, 14, 15]],
    }


def make_before(data):
    fig = make_subplots(rows=1, cols=2, subplot_titles=("Hill", "Harbor"))
    for panel, depot in enumerate(["Hill", "Harbor"], 1):
        fig.add_bar(x=WEEKS, y=data[depot][0], name=depot, marker_color="#D0B99F", row=1, col=panel)
        fig.update_yaxes(range=[10, 16] if panel == 1 else [0, 30], row=1, col=panel)
    fig.frames = [
        go.Frame(name=month, data=[go.Bar(y=data[depot][index]) for depot in ["Hill", "Harbor"]])
        for index, month in enumerate(["May", "June"])
    ]
    fig.update_layout(
        title_text="DEPOT LOAD REPORT",
        showlegend=False,
        paper_bgcolor="#FCE4C1",
        plot_bgcolor="#F3D0AB",
        updatemenus=[
            {
                "type": "buttons",
                "buttons": [
                    {"label": month, "method": "animate", "args": [[month], {"mode": "immediate"}]}
                    for month in ["May", "June"]
                ],
            }
        ],
        margin={"t": 85, "b": 50, "l": 95, "r": 20},
    )
    return fig


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