"""Amount display composite for currency values.

Displays monetary amounts in the Smartbank style with Title 01 typography.
"""

from __future__ import annotations

import pydivkit as dk

from smarty_ui.tokens.theme import Theme, default_theme


def amount_display(
    amount: str,
    *,
    currency: str = "сум",
    color: str | None = None,
    size: str = "large",
    show_currency: bool = True,
    theme: Theme = default_theme,
) -> dk.DivText:
    """Display a currency amount in Smartbank style.

    Uses Title 01 style (Bold 26px) for large amounts or Title 02 (Bold 20px)
    for smaller displays.

    Args:
        amount: The formatted amount string (e.g., "22 653 266")
        currency: Currency suffix (default "сум" for Uzbek som)
        color: Text color, defaults to text_primary
        size: "large" (Title 01) or "small" (Title 02)
        show_currency: Whether to append the currency suffix
        theme: Theme tokens to use

    Returns:
        A DivText element displaying the amount
    """
    display_text = f"{amount} {currency}" if show_currency else amount

    if size == "large":
        style = theme.typography.get_title_1()
    else:
        style = theme.typography.get_title_2()

    return dk.DivText(
        text=display_text,
        font_size=style.size,
        font_weight=dk.DivFontWeight(style.weight),
        text_color=color or theme.colors.text_primary,
        line_height=style.line_height,
        width=dk.DivWrapContentSize(),
    )


def amount_with_label(
    amount: str,
    label: str,
    *,
    currency: str = "сум",
    amount_color: str | None = None,
    label_color: str | None = None,
    theme: Theme = default_theme,
) -> dk.DivContainer:
    """Display an amount with a label above it.

    Common pattern for showing balances with a description like
    "Основной счёт" above the amount.

    Args:
        amount: The formatted amount string
        label: Label text to show above the amount
        currency: Currency suffix
        amount_color: Color for the amount text
        label_color: Color for the label text
        theme: Theme tokens to use

    Returns:
        A vertical container with label and amount
    """
    caption_style = theme.typography.get_caption_1()
    title_style = theme.typography.get_title_1()

    return dk.DivContainer(
        orientation=dk.DivContainerOrientation.VERTICAL,
        width=dk.DivWrapContentSize(),
        items=[
            dk.DivText(
                text=label,
                font_size=caption_style.size,
                font_weight=dk.DivFontWeight(caption_style.weight),
                text_color=label_color or theme.colors.text_secondary,
                line_height=caption_style.line_height,
                width=dk.DivWrapContentSize(),
            ),
            dk.DivSeparator(
                delimiter_style=dk.DivSeparatorDelimiterStyle(color="#00000000"),
                margins=dk.DivEdgeInsets(top=4),
            ),
            dk.DivText(
                text=f"{amount} {currency}",
                font_size=title_style.size,
                font_weight=dk.DivFontWeight(title_style.weight),
                text_color=amount_color or theme.colors.text_primary,
                line_height=title_style.line_height,
                width=dk.DivWrapContentSize(),
            ),
        ],
    )


def compact_amount(
    amount: str,
    *,
    currency: str = "сум",
    color: str | None = None,
    theme: Theme = default_theme,
) -> dk.DivText:
    """Display a compact amount using Text 01 style.

    Useful for list items and smaller displays where Title styles
    would be too large.

    Args:
        amount: The formatted amount string
        currency: Currency suffix
        color: Text color
        theme: Theme tokens to use

    Returns:
        A DivText element with the amount
    """
    style = theme.typography.get_text_1()

    return dk.DivText(
        text=f"{amount} {currency}",
        font_size=style.size,
        font_weight=dk.DivFontWeight(theme.typography.semibold_weight),
        text_color=color or theme.colors.text_primary,
        line_height=style.line_height,
        width=dk.DivWrapContentSize(),
    )
