import { useEffect, useRef, useState } from 'react'; import { ChevronLeft, ChevronRight } from 'lucide-react'; import MovieCard from './MovieCard'; export default function MovieSection({ title, movies = [], href = '#' }) { const [visible, setVisible] = useState(true); const sectionRef = useRef(null); const scrollRef = useRef(null); const [showLeft, setShowLeft] = useState(false); const [showRight, setShowRight] = useState(true); useEffect(() => { const observer = new IntersectionObserver( ([entry]) => { if (entry.isIntersecting) { setVisible(true); observer.unobserve(entry.target); } }, { threshold: 0.1 } ); if (sectionRef.current) observer.observe(sectionRef.current); return () => observer.disconnect(); }, []); const handleScroll = () => { if (!scrollRef.current) return; const { scrollLeft, scrollWidth, clientWidth } = scrollRef.current; setShowLeft(scrollLeft > 10); setShowRight(scrollLeft < scrollWidth - clientWidth - 10); }; const scroll = (dir) => { if (!scrollRef.current) return; const amount = scrollRef.current.clientWidth * 0.8; scrollRef.current.scrollBy({ left: dir * amount, behavior: 'smooth' }); }; if (!movies?.length) return null; return (

{title}

{href !== '#' && ( Xem tất cả )}
{showLeft && ( )} {showRight && ( )}
{movies.map((movie) => (
))}
); }