"""Configuration dataclasses and enums for the media gallery."""

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

# %% auto #0
__all__ = ['ViewMode', 'SelectionMode', 'CardSize', 'ListColumn', 'GridConfig', 'ListConfig', 'FilterConfig', 'PaginationConfig',
           'PreviewConfig', 'GalleryCallbacks', 'GalleryConfig']

# %% ../../nbs/core/config.ipynb #c3d4e5f6
from dataclasses import dataclass, field
from enum import Enum
from typing import Any, Callable, List, Literal, Optional, Tuple

from cjm_file_discovery.core.models import FileInfo, FileType

# %% ../../nbs/core/config.ipynb #e5f6a7b8
class ViewMode(str, Enum):
    """Display modes for media gallery."""
    GRID = "grid"   # Card grid layout
    LIST = "list"   # Table/list layout

# %% ../../nbs/core/config.ipynb #f6a7b8c9
class SelectionMode(str, Enum):
    """File selection modes."""
    NONE = "none"           # Browse only, no selection
    SINGLE = "single"       # Select one file
    MULTIPLE = "multiple"   # Select multiple files

# %% ../../nbs/core/config.ipynb #g7b8c9d0
class CardSize(str, Enum):
    """Card size presets for grid view."""
    SMALL = "small"     # Compact cards
    MEDIUM = "medium"   # Default size
    LARGE = "large"     # Large cards with more detail

# %% ../../nbs/core/config.ipynb #h8c9d0e1
class ListColumn(str, Enum):
    """Available columns for list view."""
    NAME = "name"
    TYPE = "type"
    SIZE = "size"
    MODIFIED = "modified"
    EXTENSION = "extension"
    PATH = "path"

# %% ../../nbs/core/config.ipynb #k1f2g3h4
@dataclass
class GridConfig:
    """Grid view display configuration."""
    columns: int = 4                       # Number of columns in grid
    card_size: CardSize = CardSize.MEDIUM  # Card size preset
    show_thumbnails: bool = True           # Show image/video thumbnails
    show_file_size: bool = True            # Show file size on cards
    show_file_type: bool = True            # Show file type badge

# %% ../../nbs/core/config.ipynb #n4i5j6k7
@dataclass
class ListConfig:
    """List view display configuration."""
    columns: List[ListColumn] = field(default_factory=lambda: [
        ListColumn.NAME, ListColumn.TYPE, ListColumn.SIZE, ListColumn.MODIFIED
    ])
    show_icons: bool = True                # Show file type icons
    striped: bool = False                  # Zebra striping for rows
    compact: bool = False                  # Compact row height

# %% ../../nbs/core/config.ipynb #q7l8m9n0
@dataclass
class FilterConfig:
    """Filter configuration for media gallery."""
    enabled_types: List[FileType] = field(default_factory=lambda: [
        FileType.AUDIO, FileType.VIDEO, FileType.IMAGE, FileType.DOCUMENT
    ])  # File types to display
    allow_type_filter: bool = True         # Show type filter controls
    show_hidden: bool = False              # Show hidden files
    custom_filter: Optional[Callable[[FileInfo], bool]] = None  # Custom filter function
    
    def matches(
        self,
        file_info: FileInfo  # File to check against filter
    ) -> bool:  # True if file passes filter
        """Check if a file matches the filter criteria."""
        # Check hidden files
        if not self.show_hidden and file_info.name.startswith('.'):
            return False
        
        # Check file type (skip directories)
        if not file_info.is_directory:
            if file_info.file_type not in self.enabled_types:
                return False
        
        # Check custom filter
        if self.custom_filter is not None:
            return self.custom_filter(file_info)
        
        return True

# %% ../../nbs/core/config.ipynb #t0o1p2q3
@dataclass
class PaginationConfig:
    """Pagination configuration."""
    items_per_page: int = 24               # Items to show per page
    show_pagination: bool = True           # Show pagination controls
    show_page_size_selector: bool = False  # Allow changing page size
    page_size_options: List[int] = field(default_factory=lambda: [12, 24, 48, 96])

# %% ../../nbs/core/config.ipynb #w3r4s5t6
@dataclass
class PreviewConfig:
    """Preview modal configuration."""
    enable_preview: bool = True            # Enable preview modal on click
    show_download_button: bool = True      # Show download button in preview
    show_info_panel: bool = True           # Show file info in preview
    show_navigation: bool = True           # Show prev/next navigation
    autoplay_video: bool = False           # Autoplay videos in preview
    autoplay_audio: bool = False           # Autoplay audio in preview

# %% ../../nbs/core/config.ipynb #z6u7v8w9
@dataclass
class GalleryCallbacks:
    """Event callbacks for gallery customization."""
    on_select: Optional[Callable[[str], None]] = None            # Called when file selected
    on_selection_change: Optional[Callable[[List[str]], None]] = None  # Called when selection changes
    on_preview: Optional[Callable[[str], None]] = None           # Called when preview opens
    on_download: Optional[Callable[[str], None]] = None          # Called when download clicked
    validate_selection: Optional[Callable[[str], Tuple[bool, str]]] = None  # Validate before select

# %% ../../nbs/core/config.ipynb #c9x0y1z2
@dataclass
class GalleryConfig:
    """Main configuration for media gallery."""
    # View settings
    default_view: ViewMode = ViewMode.GRID     # Default view mode
    allow_view_toggle: bool = True             # Allow user to toggle view mode
    
    # Sub-configurations
    grid: GridConfig = field(default_factory=GridConfig)
    list: ListConfig = field(default_factory=ListConfig)
    filter: FilterConfig = field(default_factory=FilterConfig)
    pagination: PaginationConfig = field(default_factory=PaginationConfig)
    preview: PreviewConfig = field(default_factory=PreviewConfig)
    
    # Selection
    selection_mode: SelectionMode = SelectionMode.NONE
    max_selections: Optional[int] = None       # For MULTIPLE mode
    
    # HTML IDs (for HTMX targeting)
    gallery_id: str = "media-gallery"
    content_id: str = "media-gallery-content"
    controls_id: str = "media-gallery-controls"
    preview_modal_id: str = "media-preview-modal"
    
    # Keyboard (placeholder for future integration)
    keyboard_config: Optional[Any] = None
    
    def can_select(
        self,
        file_info: FileInfo  # File to check
    ) -> bool:  # True if file can be selected
        """Check if a file can be selected based on config."""
        if self.selection_mode == SelectionMode.NONE:
            return False
        # Directories are not selectable in gallery
        if file_info.is_directory:
            return False
        return True
