import plotly.graph_objects as go


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


def load_data():
    return [
        ("Cedar", 12, 4),
        ("Elm", 8, 6),
        ("Harbor", 10, 5),
        ("Park", 6, 8),
        ("River", 7, 7),
        ("Union", 5, 9),
    ]


def value_table(data):
    return {
        "columns": ["Clinic", "Staffed exam rooms", "Clinicians on duty"],
        "rows": [list(row) for row in data],
    }


def make_after(data) -> go.Figure:
    clinics, rooms, clinicians = zip(*data, strict=True)
    fig = go.Figure()
    for axis, counts in (("x", rooms), ("x2", clinicians)):
        fig.add_scatter(
            x=counts,
            y=clinics,
            xaxis=axis,
            mode="markers+text",
            marker={"size": 9, "color": "#24688c"},
            text=counts,
            textposition="middle right",
            hoverinfo="skip",
        )
    scale = {"range": [0, 14], "dtick": 4, "anchor": "y"}
    fig.update_layout(
        template="simple_white",
        font=FONT,
        showlegend=False,
        title="Clinic capacity and staffing",
        xaxis={**scale, "domain": [0, 0.45], "title": "Staffed exam rooms"},
        xaxis2={**scale, "domain": [0.55, 1], "title": "Clinicians on duty"},
        yaxis={"autorange": "reversed", "categoryorder": "array", "categoryarray": clinics},
        margin={"l": 84, "r": 28, "t": 60, "b": 66},
    )
    return fig


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