"""Width slider, scale slider, and card count selector components."""

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

# %% auto #0
__all__ = ['render_width_slider', 'render_scale_slider', 'render_card_count_select']

# %% ../../nbs/components/controls.ipynb #ct000003
from typing import Any

from fasthtml.common import Div, Span, Input, Select, Option

# DaisyUI components
from cjm_fasthtml_daisyui.components.data_input.range_slider import range_dui, range_sizes
from cjm_fasthtml_daisyui.components.data_input.select import select, select_sizes
from cjm_fasthtml_daisyui.utilities.semantic_colors import text_dui

# Tailwind utilities
from cjm_fasthtml_tailwind.utilities.flexbox_and_grid import (
    flex_display, items, gap, grow
)
from cjm_fasthtml_tailwind.utilities.sizing import w
from cjm_fasthtml_tailwind.utilities.typography import font_size
from cjm_fasthtml_tailwind.core.base import combine_classes

# Local imports
from ..core.config import CardStackConfig
from ..core.html_ids import CardStackHtmlIds

# %% ../../nbs/components/controls.ipynb #ct000005
def render_width_slider(
    config: CardStackConfig,  # Card stack configuration
    ids: CardStackHtmlIds,  # HTML IDs for this instance
    card_width: int = 80,  # Current card width in rem
) -> Any:  # Width slider component
    """Render the card stack width slider control."""
    js_fn = f"window.cardStacks['{config.prefix}'].updateWidth(this.value)"

    return Div(
        Span(
            "Narrow",
            cls=combine_classes(font_size.xs, text_dui.base_content.opacity(50))
        ),
        Input(
            type="range",
            id=ids.width_slider,
            min=str(config.card_width_min),
            max=str(config.card_width_max),
            step=str(config.card_width_step),
            value=str(card_width),
            cls=combine_classes(range_dui, range_sizes.xs, grow()),
            oninput=js_fn
        ),
        Span(
            "Wide",
            cls=combine_classes(font_size.xs, text_dui.base_content.opacity(50))
        ),
        cls=combine_classes(flex_display, items.center, gap(3), w.full)
    )

# %% ../../nbs/components/controls.ipynb #ct000008
def render_scale_slider(
    config: CardStackConfig,  # Card stack configuration
    ids: CardStackHtmlIds,  # HTML IDs for this instance
    card_scale: int = 100,  # Current scale percentage
) -> Any:  # Scale slider component
    """Render the card stack scale slider control."""
    js_fn = f"window.cardStacks['{config.prefix}'].updateScale(this.value)"

    return Div(
        Span(
            "Smaller",
            cls=combine_classes(font_size.xs, text_dui.base_content.opacity(50))
        ),
        Input(
            type="range",
            id=ids.scale_slider,
            min=str(config.card_scale_min),
            max=str(config.card_scale_max),
            step=str(config.card_scale_step),
            value=str(card_scale),
            cls=combine_classes(range_dui, range_sizes.xs, grow()),
            oninput=js_fn
        ),
        Span(
            "Larger",
            cls=combine_classes(font_size.xs, text_dui.base_content.opacity(50))
        ),
        cls=combine_classes(flex_display, items.center, gap(3), w.full)
    )

# %% ../../nbs/components/controls.ipynb #ct000011
def render_card_count_select(
    config: CardStackConfig,  # Card stack configuration
    ids: CardStackHtmlIds,  # HTML IDs for this instance
    current_count: int = 3,  # Currently selected card count
) -> Any:  # Card count dropdown component
    """Render the card count dropdown selector."""
    js_fn = f"window.cardStacks['{config.prefix}'].handleCountChange(this.value)"

    options = []

    # Auto option (client-side JS syncs the selected state via _syncCountDropdown)
    if config.auto_visible_count:
        options.append(Option("Auto", value="auto"))

    options.extend(
        Option(
            f"{count} card{'s' if count > 1 else ''}",
            value=str(count),
            selected=(count == current_count)
        )
        for count in config.visible_count_options
    )

    return Select(
        *options,
        id=ids.card_count_select,
        cls=combine_classes(select, select_sizes.sm),
        onchange=js_fn
    )
