"""Transaction status widget block aligned with Smartbank Figma design system.

Provides transaction status widgets for displaying transfer results
with success, error, and pending states.

Figma reference:
- Success: node-id=16657:53975 (status=complete, type=transfer)
- Error: node-id=16657:53991 (status=error, type=transfer)
- Pending: node-id=16625:53316 (status=pending, type=transfer)
"""

from __future__ import annotations

from typing import Literal, TypedDict

import pydivkit as dk

from smarty_ui.composites.status_bubble import (
    status_bubble,
    transfer_success_bubble,
    transfer_error_bubble,
    transfer_pending_bubble,
)
from smarty_ui.tokens.theme import Theme, default_theme

TransactionStatus = Literal["success", "error", "pending"]


class TransactionData(TypedDict, total=False):
    """Data structure for a transaction."""

    amount: str
    recipient: str
    date_time: str
    currency: str
    status: TransactionStatus
    action_url: str | None


def transaction_status_widget(
    amount: str,
    recipient: str,
    date_time: str,
    *,
    status: TransactionStatus = "success",
    currency: str = "сум",
    action_url: str | None = None,
    theme: Theme = default_theme,
) -> dk.DivContainer:
    """Transaction status widget for displaying transfer results.

    A colored card showing the transfer status with:
    - Status label (e.g., "Перевод выполнен", "Ошибка при переводе")
    - Status icon (checkmark, X, or clock)
    - Amount in large text
    - Recipient name/card info
    - Date and time

    Design specs (from Figma):
    - Width: 350px
    - Height: 142px
    - Corner radius: 16px
    - Success: Blue gradient background (#076AE2 to #035DCA)
    - Error: Red solid background (#FF516E)
    - Pending: Grey solid background (#80858E)

    Args:
        amount: Formatted amount string (e.g., "200 000")
        recipient: Recipient name and card info (e.g., "ALEKSANDR GURYANOV ** 2221")
        date_time: Transaction date and time (e.g., "3 сентября 2023 18:27")
        status: Transaction status - "success", "error", or "pending"
        currency: Currency suffix (default "сум")
        action_url: Optional URL to navigate on tap
        theme: Theme tokens to use

    Returns:
        A DivContainer representing the transaction status widget
    """
    return status_bubble(
        amount,
        status=status,
        bubble_type="transfer",
        recipient=recipient,
        date_time=date_time,
        currency=currency,
        action_url=action_url,
        theme=theme,
    )


def transaction_success_widget(
    amount: str,
    recipient: str,
    date_time: str,
    *,
    currency: str = "сум",
    action_url: str | None = None,
    theme: Theme = default_theme,
) -> dk.DivContainer:
    """Successful transaction widget.

    Shows a blue gradient card indicating the transfer was completed.

    Args:
        amount: Formatted amount string
        recipient: Recipient name and card info
        date_time: Transaction date and time
        currency: Currency suffix
        action_url: Optional tap action URL
        theme: Theme tokens to use

    Returns:
        A transaction status widget showing success
    """
    return transfer_success_bubble(
        amount,
        recipient,
        date_time,
        currency=currency,
        action_url=action_url,
        theme=theme,
    )


def transaction_failed_widget(
    amount: str,
    recipient: str,
    date_time: str,
    *,
    currency: str = "сум",
    action_url: str | None = None,
    theme: Theme = default_theme,
) -> dk.DivContainer:
    """Failed transaction widget.

    Shows a red card indicating the transfer failed.

    Args:
        amount: Formatted amount string
        recipient: Recipient name and card info
        date_time: Transaction date and time
        currency: Currency suffix
        action_url: Optional tap action URL
        theme: Theme tokens to use

    Returns:
        A transaction status widget showing error
    """
    return transfer_error_bubble(
        amount,
        recipient,
        date_time,
        currency=currency,
        action_url=action_url,
        theme=theme,
    )


def transaction_pending_widget(
    amount: str,
    recipient: str,
    date_time: str,
    *,
    currency: str = "сум",
    action_url: str | None = None,
    theme: Theme = default_theme,
) -> dk.DivContainer:
    """Pending transaction widget.

    Shows a grey card indicating the transfer is pending.

    Args:
        amount: Formatted amount string
        recipient: Recipient name and card info
        date_time: Transaction date and time
        currency: Currency suffix
        action_url: Optional tap action URL
        theme: Theme tokens to use

    Returns:
        A transaction status widget showing pending
    """
    return transfer_pending_bubble(
        amount,
        recipient,
        date_time,
        currency=currency,
        action_url=action_url,
        theme=theme,
    )


def transaction_widget_from_data(
    data: TransactionData,
    *,
    theme: Theme = default_theme,
) -> dk.DivContainer:
    """Create a transaction widget from a data dictionary.

    Args:
        data: Transaction data dictionary
        theme: Theme tokens to use

    Returns:
        A transaction status widget
    """
    return transaction_status_widget(
        amount=data.get("amount", "0"),
        recipient=data.get("recipient", ""),
        date_time=data.get("date_time", ""),
        status=data.get("status", "success"),
        currency=data.get("currency", "сум"),
        action_url=data.get("action_url"),
        theme=theme,
    )
