"""AUTO-GENERATED by scripts/codegen.py — DO NOT EDIT."""
from __future__ import annotations

from typing import Any, Callable

from zuzu.runtime.spec import _add_component
from zuzu.record import Record, RecordQuery
from zuzu.components._utils import _check_visible



def badge(
    text: str,
    color: str = 'default',
    *,
    size: str = 'sm',
    visible: Any = True,
) -> None:
    """Badge. size: sm|md."""
    if not _check_visible(visible):
        return
    comp: dict[str, Any] = {"type": "badge", "text": text, "color": color, "size": size}
    _add_component(comp)


def card(
    title: str,
    body: str = '',
    *,
    image: str | None = None,
    background: str = 'card',
    visible: Any = True,
) -> None:
    """Card. background: card|accent|dark|highlight."""
    if not _check_visible(visible):
        return
    comp: dict[str, Any] = {"type": "card", "title": title, "body": body, "background": background}
    if image:
        comp["image"] = image
    _add_component(comp)


def chart(
    source: Record | RecordQuery | list[dict[str, Any]],
    *,
    x: str,
    y: str,
    kind: str = 'bar',
    aggregate: str | None = None,
    visible: Any = True,
) -> None:
    """Chart visualization. kind: bar|line|area|pie|donut."""
    if not _check_visible(visible):
        return
    comp: dict[str, Any] = {"type": "chart", "x": x, "y": y, "kind": kind}

    if isinstance(source, Record):
        comp["source"] = source._table_name
    elif isinstance(source, RecordQuery):
        comp["source"] = source._record._table_name
    else:
        comp["data"] = source
    if aggregate:
        comp["aggregate"] = aggregate
    _add_component(comp)


def countdown(
    target: str,
    *,
    label: str = '',
    visible: Any = True,
) -> None:
    """Countdown timer to a target date/time (ISO string)."""
    if not _check_visible(visible):
        return
    comp: dict[str, Any] = {"type": "countdown", "target": target, "label": label}
    _add_component(comp)


def embed(
    url: str,
    *,
    height: int | float = 400,
    visible: Any = True,
) -> None:
    """Embed an external webpage via iframe."""
    if not _check_visible(visible):
        return
    comp: dict[str, Any] = {"type": "embed", "url": url, "height": height}
    _add_component(comp)


def gauge(
    value: int | float,
    max: int | float = 100,
    *,
    label: str = '',
    visible: Any = True,
) -> None:
    """Ring/radial gauge for KPI dashboards."""
    if not _check_visible(visible):
        return
    comp: dict[str, Any] = {"type": "gauge", "value": value, "max": max, "label": label}
    _add_component(comp)


def grid(
    source: Record | RecordQuery | list[dict[str, Any]],
    *,
    fields: list[Any] | None = None,
    editable: bool = False,
    sort: str | None = None,
    visible: Any = True,
) -> None:
    """Data grid with optional field selection and editing."""
    if not _check_visible(visible):
        return
    comp: dict[str, Any] = {"type": "grid", "editable": editable}

    if isinstance(source, Record):
        comp["source"] = source._table_name
    elif isinstance(source, RecordQuery):
        sql, params = source._query.build_select()
        comp["source"] = source._record._table_name
        comp["query"] = {"sql": sql, "params": params}
    else:
        comp["data"] = source
    if fields:
        comp["fields"] = fields
    if sort:
        comp["sort"] = sort
    _add_component(comp)


def hint(
    text: str,
    *,
    mood: str = 'default',
    icon: str | None = None,
    visible: Any = True,
) -> None:
    """Helper text with optional mood (default|success|warning|danger)."""
    if not _check_visible(visible):
        return
    comp: dict[str, Any] = {"type": "hint", "text": text, "mood": mood}
    if icon:
        comp["icon"] = icon
    _add_component(comp)


def image(
    src: str,
    *,
    shape: str = 'square',
    size: str = 'md',
    alt: str = '',
    visible: Any = True,
) -> None:
    """Image display. shape: square|circle|full. size: sm|md|lg|full."""
    if not _check_visible(visible):
        return
    comp: dict[str, Any] = {"type": "image", "src": src, "shape": shape, "size": size, "alt": alt}
    _add_component(comp)


def list(
    source: Record | RecordQuery | list[dict[str, Any]],
    *,
    title: str | None = None,
    subtitle: str | None = None,
    badge: Any | None = None,
    image: str | None = None,
    on_click: str | None = None,
    searchable: bool = False,
    sort: str | None = None,
    empty: str = 'No items.',
    visible: Any = True,
) -> None:
    """Data-bound list with optional title, subtitle, badge, and image columns."""
    if not _check_visible(visible):
        return
    comp: dict[str, Any] = {"type": "list", "empty": empty}

    if isinstance(source, Record):
        comp["source"] = source._table_name
    elif isinstance(source, RecordQuery):
        sql, params = source._query.build_select()
        comp["source"] = source._record._table_name
        comp["query"] = {"sql": sql, "params": params}
    else:
        comp["data"] = source
    if title:
        comp["title"] = title
    if subtitle:
        comp["subtitle"] = subtitle
    if badge:
        comp["badge"] = badge
    if image:
        comp["image"] = image
    if on_click:
        comp["on_click"] = on_click
    if searchable:
        comp["searchable"] = searchable
    if sort:
        comp["sort"] = sort
    _add_component(comp)


def metric(
    label: str,
    value: Any,
    delta: Any | None = None,
    *,
    description: str | None = None,
    visible: Any = True,
) -> None:
    """Key metric display with optional delta and description."""
    if not _check_visible(visible):
        return
    comp: dict[str, Any] = {"type": "metric", "label": label, "value": 0 if value is None else value}
    if delta is not None:
        comp["delta"] = delta
    if description:
        comp["description"] = description
    _add_component(comp)


def progress(
    value: int | float,
    max: int | float = 100,
    *,
    label: str | None = None,
    color: str | None = None,
    show_value: bool = True,
    visible: Any = True,
) -> None:
    """Progress bar with optional label and color."""
    if not _check_visible(visible):
        return
    comp: dict[str, Any] = {"type": "progress", "value": value, "max": max, "show_value": show_value}
    if label:
        comp["label"] = label
    if color:
        comp["color"] = color
    _add_component(comp)


def richtext(content: str, *, visible: Any = True) -> None:
    """Render markdown content."""
    if not _check_visible(visible):
        return
    comp: dict[str, Any] = {"type": "richtext", "content": content}
    _add_component(comp)


def text(
    content: str,
    *,
    style: str = 'body',
    visible: Any = True,
) -> None:
    """Text block. style: body|caption|headline|overline."""
    if not _check_visible(visible):
        return
    comp: dict[str, Any] = {"type": "text", "text": content, "style": style}
    _add_component(comp)


def title(
    text: str,
    *,
    size: str = 'lg',
    subtitle: str | None = None,
    emphasis: str | None = None,
    visible: Any = True,
) -> None:
    """Heading. size: sm|md|lg|xl. Optional subtitle and emphasis text."""
    if not _check_visible(visible):
        return
    comp: dict[str, Any] = {"type": "title", "text": text, "size": size}
    if subtitle:
        comp["subtitle"] = subtitle
    if emphasis:
        comp["emphasis"] = emphasis
    _add_component(comp)
