import { useState, useEffect, useRef } from 'react'; import { Link, useNavigate } from 'react-router-dom'; import { useCreateEntry } from '@/hooks/useEntries'; import { useLibraryStore } from '@/stores/useLibraryStore'; import { Button } from '@/components/ui/button'; import { Star, Plus, Play, Search, ChevronLeft, ChevronRight } from 'lucide-react'; import type { TmdbEntry } from '@/types'; interface HeroSliderProps { entries: TmdbEntry[]; } export function HeroSlider({ entries }: HeroSliderProps) { const navigate = useNavigate(); const [activeIndex, setActiveIndex] = useState(0); const [searchInput, setSearchInput] = useState(''); const intervalRef = useRef | null>(null); const createEntry = useCreateEntry(); const libraryEntries = useLibraryStore((s) => s.entries); const slides = entries.slice(0, 8); const go = (idx: number) => { setActiveIndex((idx + slides.length) % slides.length); }; const startAutoplay = () => { if (intervalRef.current) clearInterval(intervalRef.current); if (slides.length === 0) return; intervalRef.current = setInterval( () => setActiveIndex((i) => (i + 1) % slides.length), 6000, ); }; useEffect(() => { startAutoplay(); return () => { if (intervalRef.current) clearInterval(intervalRef.current); }; // eslint-disable-next-line react-hooks/exhaustive-deps }, [slides.length]); const handleSearch = () => { const q = searchInput.trim(); if (q) navigate(`/search?q=${encodeURIComponent(q)}`); }; if (slides.length === 0) return null; return (
{/* Slide track */}
{slides.map((entry) => { const title = entry.title || entry.name || 'Untitled'; const backdrop = entry.backdrop_path ? `https://image.tmdb.org/t/p/original${entry.backdrop_path}` : null; const isTv = entry.media_type === 'tv' || !!entry.name; const matchedEntry = Array.from(libraryEntries.values()).find( (e) => e.entryIds?.tmdb_id === entry.id, ); return (
{backdrop ? ( ) : (
)}
{/* Per-slide info */}
{isTv ? 'Series' : 'Movie'} {entry.vote_average > 0 && ( {entry.vote_average.toFixed(1)} )}

{title}

{entry.overview && (

{entry.overview}

)}
{matchedEntry ? ( ) : ( )}
); })}
{/* Search bar */}
setSearchInput(e.target.value)} onKeyDown={(e) => e.key === 'Enter' && handleSearch()} className="w-full rounded-full border border-white/20 bg-black/40 py-2.5 pl-9 pr-4 text-sm text-white backdrop-blur-md placeholder-white/50 transition-colors focus:border-white/50 focus:outline-none" />
{/* Left arrow */} {/* Right arrow */} {/* Dot indicators */}
{slides.map((_, i) => (
); }