import { useRef, useState, useEffect } from 'react'; import { ChevronLeft, ChevronRight } from 'lucide-react'; import TopTenCard from './TopTenCard'; export default function TopTenSection({ series = [], rated = [], favorited = [] }) { const [activeTab, setActiveTab] = useState('series'); const scrollRef = useRef(null); const [showLeft, setShowLeft] = useState(false); const [showRight, setShowRight] = useState(true); const getMoviesForTab = () => { switch (activeTab) { case 'rated': return rated; case 'favorited': return favorited; case 'series': default: return series; } }; const movies = getMoviesForTab(); 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' }); }; // Reset scroll position on tab change useEffect(() => { if (scrollRef.current) { scrollRef.current.scrollLeft = 0; handleScroll(); } }, [activeTab]); if (!movies?.length) return null; return (
{/* Header Tabs */}

Bảng Xếp Hạng

{/* Premium Tab Buttons */}
{[ { id: 'series', name: 'Top Phim Bộ', icon: 'fa-fire' }, { id: 'rated', name: 'Đánh Giá Cao', icon: 'fa-star' }, { id: 'favorited', name: 'Yêu Thích Nhất', icon: 'fa-heart' } ].map(tab => ( ))}
{/* Row có scroll ngang */}
{/* Nút trái */} {showLeft && ( )} {/* Nút phải */} {showRight && ( )} {/* Track */}
{movies.slice(0, 10).map((movie, idx) => (
))}
); }