'use client' import * as React from 'react' import { Loader2 } from 'lucide-react' import { cn } from '../../lib/utils' import type { SlideData } from './types' export interface SlideFilmstripProps { slides: SlideData[] activeId?: string onSelect: (id: string) => void /** Drag-to-reorder: emits source + target 0-based indices on drop. Enables DnD. */ onReorder?: (fromIndex: number, toIndex: number) => void /** `horizontal` (default) for a bottom strip, `vertical` for a side rail. */ orientation?: 'horizontal' | 'vertical' className?: string } /** * Scrollable strip of slide thumbnails. Highlights the active slide and emits * its id on click. App-agnostic. */ export function SlideFilmstrip({ slides, activeId, onSelect, onReorder, orientation = 'horizontal', className, }: SlideFilmstripProps) { const dragIndex = React.useRef(null) return (
{slides.map((slide, idx) => { const active = slide.id === activeId const status = slide.status ?? (slide.imageUrl ? 'ready' : 'pending') const dnd = onReorder ? { draggable: true, onDragStart: () => { dragIndex.current = idx }, onDragOver: (e: React.DragEvent) => e.preventDefault(), onDrop: (e: React.DragEvent) => { e.preventDefault() const from = dragIndex.current dragIndex.current = null if (from !== null && from !== idx) onReorder(from, idx) }, } : {} return ( ) })}
) }