"""Check a user-supplied palette against WCAG contrast thresholds."""

from a11yviz._rules import check_level, contrast_ratio


def check_palette(colors, bg: str = "#ffffff", level: str = "AA") -> list[dict]:
    """Check pairwise color-vs-background contrast against WCAG thresholds.

    Works on any palette: ``viridis``, ``matplotlib`` colormaps,
    ``plotly`` discrete sequences, or a custom hex list. ``bg`` defaults
    to ``"#ffffff"`` for light themes; pass ``"#1a1a1a"`` for dark.
    Returns a list of dicts with keys ``color``, ``bg``, ``ratio``,
    ``status``.
    """
    level = check_level(level)
    threshold = 4.5 if level == "AA" else 7.0
    return [
        {
            "color":  c,
            "bg":     bg,
            "ratio":  round(contrast_ratio(c, bg), 2),
            "status": "ok" if contrast_ratio(c, bg) >= threshold else "todo",
        }
        for c in colors
    ]
