"""Data models for virtual collection state, configuration, column definitions, render contexts, and URL bundles."""

# AUTOGENERATED! DO NOT EDIT! File to edit: ../../nbs/core/models.ipynb.

# %% auto #0
__all__ = ['ColumnDef', 'VirtualCollectionConfig', 'VirtualCollectionState', 'RowRenderContext', 'CellRenderContext',
           'VirtualCollectionUrls']

# %% ../../nbs/core/models.ipynb #6cd67060
from dataclasses import dataclass, field
from typing import Optional, Tuple

# %% ../../nbs/core/models.ipynb #bcf30772
_prefix_counter: int = 0

def _auto_prefix() -> str:  # Auto-generated prefix like 'vc0', 'vc1', etc.
    """Generate a unique prefix for a virtual collection instance."""
    global _prefix_counter
    p = f"vc{_prefix_counter}"
    _prefix_counter += 1
    return p

# %% ../../nbs/core/models.ipynb #43d02275
@dataclass
class ColumnDef:
    """Column definition for table layout."""
    key: str                            # Unique column identifier (used in cell IDs)
    header: str = ""                    # Display text for header
    sortable: bool = False              # Whether column header is clickable for sort
    header_cls: str = ""                # Additional CSS classes for header cell
    cell_cls: str = ""                  # Additional CSS classes for data cells

# %% ../../nbs/core/models.ipynb #535b1c39
@dataclass
class VirtualCollectionConfig:
    """Initialization-time configuration for a virtual collection."""
    prefix: str = ""                                    # HTML ID prefix (auto-generated if empty)
    layout: str = "table"                               # 'table' or 'grid'

    # Table layout
    columns: Tuple[ColumnDef, ...] = ()                 # Column definitions

    # Grid layout
    columns_per_row: int = 4                            # Items per grid row
    grid_gap: str = "1rem"                              # Gap between grid items

    # Scroll/touch
    disable_scroll_in_modes: Tuple[str, ...] = ()       # Mode-based scroll suppression

    # Scrollbar
    show_scrollbar: bool = True                         # Show custom scrollbar
    min_thumb_height: int = 24                          # Minimum scrollbar thumb height (px)

    def __post_init__(self):
        if not self.prefix:
            self.prefix = _auto_prefix()

# %% ../../nbs/core/models.ipynb #93e1711b
@dataclass
class VirtualCollectionState:
    """Mutable runtime state for a virtual collection."""
    window_start: int = 0               # First visible row index
    visible_rows: int = 0               # Number of visible rows (from auto-fit)
    total_items: int = 0                # Total item count (set by consumer)
    viewport_height: float = 0.0        # Measured viewport height (px)
    is_auto_mode: bool = True           # Auto-adjust visible rows from viewport
    cursor_index: int = -1              # Keyboard cursor position (-1 = none)
    sort_column: str = ""               # Current sort column key (empty = unsorted)
    sort_ascending: bool = True         # Sort direction

# %% ../../nbs/core/models.ipynb #93b1336a
@dataclass
class RowRenderContext:
    """Context passed to row/item render callback."""
    index: int                          # Row index in the full collection
    total_items: int                    # Total item count
    is_cursor: bool = False             # Whether this row is the keyboard cursor
    is_first_visible: bool = False      # First row in current window
    is_last_visible: bool = False       # Last row in current window

# %% ../../nbs/core/models.ipynb #de7b7783
@dataclass
class CellRenderContext:
    """Context passed to cell render callback."""
    row_index: int                      # Row index in the full collection
    column: ColumnDef                   # Column definition
    total_items: int                    # Total item count
    is_cursor: bool = False             # Whether this row is the keyboard cursor

# %% ../../nbs/core/models.ipynb #07d56db4
@dataclass
class VirtualCollectionUrls:
    """URL bundle for HTMX endpoints."""
    # Navigation
    nav_up: str = ""                    # Navigate up one row
    nav_down: str = ""                  # Navigate down one row
    nav_page_up: str = ""               # Navigate up one page
    nav_page_down: str = ""             # Navigate down one page
    nav_first: str = ""                 # Navigate to first row
    nav_last: str = ""                  # Navigate to last row
    nav_to_index: str = ""              # Navigate to specific row index

    # Viewport
    update_viewport: str = ""           # Update visible_rows (auto-fit)

    # Focus
    focus_row: str = ""                 # Move cursor to a specific row (click/tap)

    # Actions
    activate: str = ""                  # Activate focused row (Space/Enter)

    # Scrollbar
    scrollbar_focus: str = ""           # Move cursor via scrollbar drag/click (no refocus)

    # Sort
    sort: str = ""                      # Sort by column (header click)
