"""Typography design tokens for the smarty_ui component library.

Aligned with Smartbank Figma design system using Manrope font.
"""

from dataclasses import dataclass
from typing import NamedTuple


class TextStyle(NamedTuple):
    """Defines a complete text style with all properties."""

    size: int
    weight: str
    line_height: int
    letter_spacing: float  # in percentage, e.g., -1 means -1%


@dataclass(frozen=True)
class TypographyTokens:
    """Immutable typography scale based on Smartbank design system.

    All sizes are in sp (scale-independent pixels) matching DivKit conventions.
    Uses Manrope font family.
    """

    # Font family
    font_family: str = "Manrope"

    # Font weights (mapped to pydivkit DivFontWeight enum values)
    # Note: pydivkit only supports: light, medium, regular, bold
    # "semibold" from Figma is mapped to "medium" as the closest match
    regular_weight: str = "regular"
    medium_weight: str = "medium"
    semibold_weight: str = "medium"  # Closest to semibold in DivKit
    bold_weight: str = "bold"

    # Title styles
    title_1_size: int = 26
    title_1_line_height: int = 32
    title_1_letter_spacing: float = -1.0

    title_2_size: int = 20
    title_2_line_height: int = 26
    title_2_letter_spacing: float = -1.0

    # Controls styles (for buttons and interactive elements)
    controls_1_size: int = 16
    controls_1_line_height: int = 24
    controls_1_letter_spacing: float = -1.0

    controls_2_size: int = 14
    controls_2_line_height: int = 20
    controls_2_letter_spacing: float = 0.0

    # Text styles (body text)
    text_1_size: int = 14
    text_1_line_height: int = 20
    text_1_letter_spacing: float = 0.0

    text_2_size: int = 12
    text_2_line_height: int = 18
    text_2_letter_spacing: float = 0.0

    text_3_size: int = 12
    text_3_line_height: int = 18
    text_3_letter_spacing: float = 0.0

    # Caption styles (small text)
    caption_1_size: int = 12
    caption_1_line_height: int = 18
    caption_1_letter_spacing: float = 0.0

    caption_2_size: int = 10
    caption_2_line_height: int = 14
    caption_2_letter_spacing: float = 2.0

    caption_3_size: int = 10
    caption_3_line_height: int = 12
    caption_3_letter_spacing: float = 2.0

    # Legacy compatibility (mapped to new styles)
    h1_size: int = 26  # maps to title_1
    h2_size: int = 20  # maps to title_2
    h3_size: int = 16  # maps to controls_1
    h4_size: int = 14  # maps to controls_2
    body_size: int = 14  # maps to text_1
    caption_size: int = 12  # maps to caption_1
    small_size: int = 10  # maps to caption_2
    default_weight: str = "regular"
    default_line_height: int = 0  # 0 = auto in DivKit

    def get_title_1(self) -> TextStyle:
        """Get Title 01 style: Bold 26px."""
        return TextStyle(
            size=self.title_1_size,
            weight=self.bold_weight,
            line_height=self.title_1_line_height,
            letter_spacing=self.title_1_letter_spacing,
        )

    def get_title_2(self) -> TextStyle:
        """Get Title 02 style: Bold 20px."""
        return TextStyle(
            size=self.title_2_size,
            weight=self.bold_weight,
            line_height=self.title_2_line_height,
            letter_spacing=self.title_2_letter_spacing,
        )

    def get_controls_1(self, bold: bool = True) -> TextStyle:
        """Get Controls 01 style: Bold/SemiBold 16px."""
        return TextStyle(
            size=self.controls_1_size,
            weight=self.bold_weight if bold else self.semibold_weight,
            line_height=self.controls_1_line_height,
            letter_spacing=self.controls_1_letter_spacing,
        )

    def get_controls_2(self, bold: bool = False) -> TextStyle:
        """Get Controls 02 style: SemiBold/Bold 14px."""
        return TextStyle(
            size=self.controls_2_size,
            weight=self.bold_weight if bold else self.semibold_weight,
            line_height=self.controls_2_line_height,
            letter_spacing=self.controls_2_letter_spacing,
        )

    def get_text_1(self) -> TextStyle:
        """Get Text 01 style: Medium 14px."""
        return TextStyle(
            size=self.text_1_size,
            weight=self.medium_weight,
            line_height=self.text_1_line_height,
            letter_spacing=self.text_1_letter_spacing,
        )

    def get_text_2(self) -> TextStyle:
        """Get Text 02 style: Medium 12px."""
        return TextStyle(
            size=self.text_2_size,
            weight=self.medium_weight,
            line_height=self.text_2_line_height,
            letter_spacing=self.text_2_letter_spacing,
        )

    def get_text_3(self) -> TextStyle:
        """Get Text 03 style: Bold 12px."""
        return TextStyle(
            size=self.text_3_size,
            weight=self.bold_weight,
            line_height=self.text_3_line_height,
            letter_spacing=self.text_3_letter_spacing,
        )

    def get_caption_1(self) -> TextStyle:
        """Get Caption 01 style: SemiBold 12px."""
        return TextStyle(
            size=self.caption_1_size,
            weight=self.semibold_weight,
            line_height=self.caption_1_line_height,
            letter_spacing=self.caption_1_letter_spacing,
        )

    def get_caption_2(self) -> TextStyle:
        """Get Caption 02 style: Medium 10px."""
        return TextStyle(
            size=self.caption_2_size,
            weight=self.medium_weight,
            line_height=self.caption_2_line_height,
            letter_spacing=self.caption_2_letter_spacing,
        )

    def get_caption_3(self) -> TextStyle:
        """Get Caption 03 style: Bold 10px."""
        return TextStyle(
            size=self.caption_3_size,
            weight=self.bold_weight,
            line_height=self.caption_3_line_height,
            letter_spacing=self.caption_3_letter_spacing,
        )
