"""One-shot accessibility wrapper."""

from a11yviz.alt_text import alt_text
from a11yviz.layout import layout


def make_a11y(fig, level: str = "AA", alt: str | None = None):
    """Apply layout + (optional) alt text in one call.

    Detects plotly Figures automatically. Matplotlib figures should be
    wrapped with the ``theme()`` context manager at creation time, then
    passed here only for alt text.
    """
    if type(fig).__module__.startswith("plotly."):
        fig = layout(fig, level=level)
        if alt is not None:
            fig = alt_text(fig, alt)
        return fig
    if type(fig).__module__.startswith("matplotlib."):
        if alt is not None:
            fig = alt_text(fig, alt)
        return fig
    raise TypeError(f"make_a11y() supports plotly and matplotlib figures, got {type(fig).__name__}")
