"""Icon + label molecule: a small icon paired with a text label."""

from __future__ import annotations

import pydivkit as dk

from smarty_ui.primitives.text import label
from smarty_ui.primitives.image import icon
from smarty_ui._helpers import hstack
from smarty_ui.tokens.theme import Theme, default_theme


def icon_label(
    icon_url: str,
    text: str,
    *,
    icon_size: int = 20,
    text_size: int | None = None,
    text_color: str | None = None,
    tint_color: str | None = None,
    gap: int = 6,
    action_url: str | None = None,
    theme: Theme = default_theme,
) -> dk.DivContainer:
    """Horizontal icon + label pair.

    Useful for menu items, metadata rows, tag-like chips, etc.
    """
    row = hstack(
        icon(icon_url, size=icon_size, tint_color=tint_color, theme=theme),
        label(text, size=text_size, color=text_color, theme=theme),
        gap=gap,
    )
    if action_url:
        row.actions = [dk.DivAction(log_id=f"icon_label_{text}", url=action_url)]
    return row
