"""Badge molecule: small colored pill for status, counts, or tags."""

from __future__ import annotations

import pydivkit as dk

from smarty_ui.tokens.theme import Theme, default_theme


def badge(
    text: str,
    *,
    bg_color: str | None = None,
    text_color: str | None = None,
    size: int | None = None,
    corner_radius: int = 12,
    padding_h: int = 8,
    padding_v: int = 2,
    theme: Theme = default_theme,
) -> dk.DivContainer:
    """Small colored pill badge.

    Useful for status indicators ("Active"), counts ("3"), or tags.
    """
    return dk.DivContainer(
        orientation=dk.DivContainerOrientation.HORIZONTAL,
        content_alignment_horizontal=dk.DivContentAlignmentHorizontal.CENTER,
        content_alignment_vertical=dk.DivContentAlignmentVertical("center"),
        width=dk.DivWrapContentSize(),
        border=dk.DivBorder(corner_radius=corner_radius),
        paddings=dk.DivEdgeInsets(
            left=padding_h,
            right=padding_h,
            top=padding_v,
            bottom=padding_v,
        ),
        background=[
            dk.DivSolidBackground(color=bg_color or theme.colors.primary),
        ],
        items=[
            dk.DivText(
                text=text,
                font_size=size or theme.typography.caption_size,
                font_weight=dk.DivFontWeight(theme.typography.medium_weight),
                text_color=text_color or theme.colors.text_on_primary,
                width=dk.DivWrapContentSize(),
            ),
        ],
    )


def outline_badge(
    text: str,
    *,
    border_color: str | None = None,
    text_color: str | None = None,
    size: int | None = None,
    corner_radius: int = 12,
    padding_h: int = 8,
    padding_v: int = 2,
    theme: Theme = default_theme,
) -> dk.DivContainer:
    """Outlined (hollow) pill badge -- border only, no fill."""
    color = border_color or theme.colors.primary
    return dk.DivContainer(
        orientation=dk.DivContainerOrientation.HORIZONTAL,
        content_alignment_horizontal=dk.DivContentAlignmentHorizontal.CENTER,
        content_alignment_vertical=dk.DivContentAlignmentVertical("center"),
        width=dk.DivWrapContentSize(),
        border=dk.DivBorder(
            corner_radius=corner_radius,
            stroke=dk.DivStroke(color=color, width=1),
        ),
        paddings=dk.DivEdgeInsets(
            left=padding_h,
            right=padding_h,
            top=padding_v,
            bottom=padding_v,
        ),
        items=[
            dk.DivText(
                text=text,
                font_size=size or theme.typography.caption_size,
                font_weight=dk.DivFontWeight(theme.typography.medium_weight),
                text_color=text_color or color,
                width=dk.DivWrapContentSize(),
            ),
        ],
    )
