"""Numbered avatar composite aligned with Smartbank Figma design system.

Provides circular avatar with number/letter for contact lists and indices.
"""

from __future__ import annotations

import pydivkit as dk

from smarty_ui.tokens.theme import Theme, default_theme


def numbered_avatar(
    number: int | str,
    *,
    size: int = 32,
    bg_color: str | None = None,
    text_color: str | None = None,
    theme: Theme = default_theme,
) -> dk.DivContainer:
    """Circular avatar with a number or letter inside.

    Used for contact lists, numbered items, and index indicators.

    Args:
        number: Number or text to display (e.g., 1, 2, "A", "B")
        size: Avatar size in dp (default 32)
        bg_color: Background color, defaults to blue-light
        text_color: Text color, defaults to primary blue
        theme: Theme tokens to use

    Returns:
        A DivContainer representing the numbered avatar
    """
    # Get typography style - Text 03 Bold 12px
    text_style = theme.typography.get_text_3()

    # Build text element
    text_element = dk.DivText(
        text=str(number),
        font_size=text_style.size,
        font_weight=dk.DivFontWeight(text_style.weight),
        text_color=text_color or theme.colors.primary,
        line_height=text_style.line_height,
        text_alignment_horizontal=dk.DivAlignmentHorizontal.CENTER,
        width=dk.DivWrapContentSize(),
    )

    # Build circular container
    return dk.DivContainer(
        orientation=dk.DivContainerOrientation.HORIZONTAL,
        content_alignment_horizontal=dk.DivContentAlignmentHorizontal.CENTER,
        content_alignment_vertical=dk.DivAlignmentVertical.CENTER,
        width=dk.DivFixedSize(value=size),
        height=dk.DivFixedSize(value=size),
        border=dk.DivBorder(corner_radius=size),  # Fully rounded
        background=[dk.DivSolidBackground(color=bg_color or theme.colors.blue_light)],
        items=[text_element],
    )


def letter_avatar(
    letter: str,
    *,
    size: int = 32,
    bg_color: str | None = None,
    text_color: str | None = None,
    theme: Theme = default_theme,
) -> dk.DivContainer:
    """Convenience function for letter-based avatar.

    Args:
        letter: Single letter to display (typically first letter of name)
        size: Avatar size in dp
        bg_color: Background color
        text_color: Text color
        theme: Theme tokens to use

    Returns:
        A circular avatar with the letter
    """
    return numbered_avatar(
        letter.upper()[:1],
        size=size,
        bg_color=bg_color,
        text_color=text_color,
        theme=theme,
    )
