"""Smarty button primitive aligned with Smartbank Figma design system.

Provides the "Smarty" style button - an outline button with blue border
and blue text, used for secondary actions like "Cancel" or "Skip".

Figma reference: node-id=15629:7862
"""

from __future__ import annotations

import pydivkit as dk

from smarty_ui.tokens.theme import Theme, default_theme


def smarty_button(
    text: str,
    *,
    action_url: str | None = None,
    width: int | None = None,
    theme: Theme = default_theme,
) -> dk.DivContainer:
    """Smarty outline button with blue border and blue text.

    A lightweight button style used for secondary actions like
    "Cancel", "Skip", or "Later".

    Design specs (from Figma):
    - Background: white
    - Border: 1px solid rgba(7, 106, 226, 0.2) (blue with 20% opacity)
    - Border radius: 16px
    - Padding: 8px vertical, 12px horizontal
    - Text: 12px Medium, blue (#076AE2)
    - Line height: 18px

    Args:
        text: Button label text
        action_url: Optional URL to navigate to on click
        width: Optional fixed width in dp, defaults to wrap content
        theme: Theme tokens to use

    Returns:
        A DivContainer representing the smarty button
    """
    # Typography: Text 02 Medium 12px
    text_style = theme.typography.get_text_2()

    # Border color: blue with 20% opacity
    # #076AE2 with 33 (20% of 255 = 51 = 0x33) alpha
    border_color = "#076AE233"

    # Build action if URL provided
    actions = None
    if action_url:
        actions = [dk.DivAction(log_id=f"smarty_btn_{text}", url=action_url)]

    return dk.DivContainer(
        orientation=dk.DivContainerOrientation.HORIZONTAL,
        content_alignment_horizontal=dk.DivContentAlignmentHorizontal.CENTER,
        content_alignment_vertical=dk.DivAlignmentVertical.CENTER,
        width=dk.DivFixedSize(value=width) if width else dk.DivWrapContentSize(),
        height=dk.DivWrapContentSize(),
        border=dk.DivBorder(
            corner_radius=16,
            stroke=dk.DivStroke(color=border_color, width=1),
        ),
        background=[dk.DivSolidBackground(color=theme.colors.background)],
        paddings=dk.DivEdgeInsets(
            left=12,
            right=12,
            top=8,
            bottom=8,
        ),
        actions=actions,
        items=[
            dk.DivText(
                text=text,
                font_size=text_style.size,
                font_weight=dk.DivFontWeight(text_style.weight),
                text_color=theme.colors.primary,
                line_height=text_style.line_height,
                width=dk.DivWrapContentSize(),
            ),
        ],
    )


def smarty_button_filled(
    text: str,
    *,
    action_url: str | None = None,
    width: int | None = None,
    theme: Theme = default_theme,
) -> dk.DivContainer:
    """Smarty filled button with blue background and white text.

    A variant of the smarty button with filled background for
    primary actions.

    Args:
        text: Button label text
        action_url: Optional URL to navigate to on click
        width: Optional fixed width in dp, defaults to wrap content
        theme: Theme tokens to use

    Returns:
        A DivContainer representing the filled smarty button
    """
    # Typography: Text 02 Medium 12px
    text_style = theme.typography.get_text_2()

    # Build action if URL provided
    actions = None
    if action_url:
        actions = [dk.DivAction(log_id=f"smarty_btn_filled_{text}", url=action_url)]

    return dk.DivContainer(
        orientation=dk.DivContainerOrientation.HORIZONTAL,
        content_alignment_horizontal=dk.DivContentAlignmentHorizontal.CENTER,
        content_alignment_vertical=dk.DivAlignmentVertical.CENTER,
        width=dk.DivFixedSize(value=width) if width else dk.DivWrapContentSize(),
        height=dk.DivWrapContentSize(),
        border=dk.DivBorder(corner_radius=16),
        background=[dk.DivSolidBackground(color=theme.colors.primary)],
        paddings=dk.DivEdgeInsets(
            left=12,
            right=12,
            top=8,
            bottom=8,
        ),
        actions=actions,
        items=[
            dk.DivText(
                text=text,
                font_size=text_style.size,
                font_weight=dk.DivFontWeight(text_style.weight),
                text_color=theme.colors.text_on_primary,
                line_height=text_style.line_height,
                width=dk.DivWrapContentSize(),
            ),
        ],
    )
