"""Loading, empty, and placeholder card components for the card stack viewport."""

# AUTOGENERATED! DO NOT EDIT! File to edit: ../../nbs/components/states.ipynb.

# %% auto #0
__all__ = ['render_placeholder_card', 'render_loading_state', 'render_empty_state']

# %% ../../nbs/components/states.ipynb #s1000003
from typing import Any, Literal

from fasthtml.common import Div, P, Span

# DaisyUI components
from cjm_fasthtml_daisyui.components.data_display.card import card, card_body
from cjm_fasthtml_daisyui.components.feedback.loading import loading, loading_styles, loading_sizes
from cjm_fasthtml_daisyui.utilities.semantic_colors import bg_dui, text_dui

# Tailwind utilities
from cjm_fasthtml_tailwind.utilities.borders import border, border_color
from cjm_fasthtml_tailwind.utilities.effects import shadow
from cjm_fasthtml_tailwind.utilities.flexbox_and_grid import (
    flex_display, flex_direction, items, justify, grow
)
from cjm_fasthtml_tailwind.utilities.spacing import p, m
from cjm_fasthtml_tailwind.utilities.sizing import w
from cjm_fasthtml_tailwind.utilities.typography import font_size, italic, text_align
from cjm_fasthtml_tailwind.core.base import combine_classes

# Local imports
from ..core.html_ids import CardStackHtmlIds

# %% ../../nbs/components/states.ipynb #s1000005
def render_placeholder_card(
    placeholder_type: Literal["start", "end"],  # Which edge of the list
) -> Any:  # Placeholder card component
    """Render a placeholder card for viewport edges."""
    text = "Beginning" if placeholder_type == "start" else "End"

    return Div(
        Div(
            P(
                text,
                cls=combine_classes(
                    font_size.lg, italic,
                    text_dui.base_content.opacity(30),
                    p.y(4)
                )
            ),
            cls=combine_classes(card_body, p(4))
        ),
        cls=combine_classes(
            card, "placeholder-card",
            bg_dui.base_100.opacity(50), shadow.none,
            border(2), border_color.transparent
        ),
        data_placeholder_type=placeholder_type
    )

# %% ../../nbs/components/states.ipynb #s1000008
def render_loading_state(
    ids: CardStackHtmlIds,  # HTML IDs for this card stack instance
    message: str = "Loading...",  # Loading message text
) -> Any:  # Loading component
    """Render loading state with spinner and message."""
    return Div(
        Div(
            Span(cls=combine_classes(loading, loading_styles.spinner, loading_sizes.lg)),
            P(
                message,
                cls=combine_classes(m.t(4), text_dui.base_content.opacity(60))
            ),
            cls=combine_classes(
                flex_display, flex_direction.col, items.center, justify.center,
                p(16)
            )
        ),
        id=ids.loading
    )

# %% ../../nbs/components/states.ipynb #s1000011
def render_empty_state(
    ids: CardStackHtmlIds,  # HTML IDs for this card stack instance
    title: str = "No items available",  # Main empty state message
    subtitle: str = "",  # Optional subtitle text
) -> Any:  # Empty state component
    """Render empty state when no items exist."""
    return Div(
        P(
            title,
            cls=combine_classes(
                text_dui.base_content.opacity(40),
                text_align.center, font_size.lg
            )
        ),
        P(
            subtitle,
            cls=combine_classes(
                text_dui.base_content.opacity(30),
                text_align.center, font_size.sm, m.t(2)
            )
        ) if subtitle else None,
        id=ids.card_stack_empty,
        cls=combine_classes(
            flex_display, flex_direction.col, items.center, justify.center,
            p(16), grow()
        )
    )
