File size: 4,631 Bytes
4bea261
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
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 (
    <section className="mx-auto max-w-7xl px-4 py-10 md:px-8 overflow-hidden">
      {/* Header Tabs */}
      <div className="mb-10 flex flex-col md:flex-row md:items-center justify-between gap-6 border-b border-white/5 pb-5">
        <div className="flex items-center gap-3">
          <span className="h-8 w-2 rounded-full bg-primary shadow-[0_0_20px_rgba(229,9,20,0.6)]" />
          <h2 className="text-2xl font-black uppercase tracking-tight text-white">
            Bảng Xếp Hạng
          </h2>
        </div>
        
        {/* Premium Tab Buttons */}
        <div className="flex flex-wrap gap-2 bg-white/5 p-1 rounded-2xl border border-white/5 backdrop-blur-md self-start md:self-auto">
          {[
            { 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 => (
            <button
              key={tab.id}
              onClick={() => setActiveTab(tab.id)}
              className={`flex items-center gap-2 px-5 py-2.5 rounded-xl text-[10px] font-black uppercase tracking-widest transition-all duration-300 cursor-pointer ${
                activeTab === tab.id
                  ? 'bg-primary text-white shadow-[0_0_20px_rgba(229,9,20,0.3)] scale-[1.02]'
                  : 'text-gray-400 hover:text-white hover:bg-white/5'
              }`}
            >
              <i className={`fas ${tab.icon} text-[9px] ${activeTab === tab.id ? 'text-white' : 'text-gray-500'}`}></i>
              {tab.name}
            </button>
          ))}
        </div>
      </div>

      {/* Row có scroll ngang */}
      <div className="relative group/section">
        {/* Nút trái */}
        {showLeft && (
          <button
            onClick={() => scroll(-1)}
            className="absolute left-1 top-[42%] z-40 -translate-y-1/2 flex h-10 w-10 items-center justify-center rounded-full bg-black/80 text-white backdrop-blur-sm opacity-0 transition-all duration-300 group-hover/section:opacity-100 hover:bg-primary border border-white/10 shadow-lg cursor-pointer"
          >
            <ChevronLeft size={20} />
          </button>
        )}

        {/* Nút phải */}
        {showRight && (
          <button
            onClick={() => scroll(1)}
            className="absolute right-1 top-[42%] z-40 -translate-y-1/2 flex h-10 w-10 items-center justify-center rounded-full bg-black/80 text-white backdrop-blur-sm opacity-0 transition-all duration-300 group-hover/section:opacity-100 hover:bg-primary border border-white/10 shadow-lg cursor-pointer"
          >
            <ChevronRight size={20} />
          </button>
        )}

        {/* Track */}
        <div
          ref={scrollRef}
          onScroll={handleScroll}
          className="scrollbar-hide flex overflow-x-auto pb-16 pt-2 px-4 md:px-8 gap-6 md:gap-8"
        >
          {movies.slice(0, 10).map((movie, idx) => (
            <div
              key={`${movie._id || movie.slug}-${activeTab}-${idx}`}
              className="w-[180px] md:w-[240px] flex-shrink-0"
            >
              <TopTenCard movie={movie} index={idx} />
            </div>
          ))}
        </div>
      </div>
    </section>
  );
}