import { useEffect, useRef, useState } from 'react'; import { ChevronLeft, ChevronRight, Play, Star, Calendar, Clock } from 'lucide-react'; export default function MovieSlider({ movies = [] }) { const containerRef = useRef(null); const [canScrollLeft, setCanScrollLeft] = useState(false); const [canScrollRight, setCanScrollRight] = useState(true); const checkScroll = () => { const el = containerRef.current; if (!el) return; setCanScrollLeft(el.scrollLeft > 0); setCanScrollRight(el.scrollLeft + el.clientWidth < el.scrollWidth - 10); }; useEffect(() => { checkScroll(); const el = containerRef.current; if (el) { el.addEventListener('scroll', checkScroll); window.addEventListener('resize', checkScroll); return () => { el.removeEventListener('scroll', checkScroll); window.removeEventListener('resize', checkScroll); }; } }, [movies]); const scroll = (dir) => { const el = containerRef.current; if (!el) return; el.scrollBy({ left: dir * el.clientWidth * 0.8, behavior: 'smooth' }); }; if (!movies?.length) return null; return (
Đề xuất hot
{movies.map((movie) => { const thumb = movie.thumb_url || movie.poster_url || ''; const year = movie.year || (movie.modified?.time ? new Date(movie.modified.time).getFullYear() : ''); return (
{movie.name} { e.currentTarget.src = 'https://via.placeholder.com/640x360/1a1a1a/888?text=No+Image'; }} />
{movie.quality && ( {movie.quality} )}

{movie.name}

{year && {year}} {movie.time && {movie.time}} {movie.tmdb?.vote_average && ( {movie.tmdb.vote_average.toFixed(1)} )}
); })}
{canScrollLeft && ( )} {canScrollRight && ( )}
); }