"use client"; import { useRef, useState, useEffect, useCallback } from "react"; import Link from "next/link"; type TrendingManga = { slug: string; title: string; coverUrl: string; genre: string; }; function RankNumber({ rank }: { rank: number }) { // Webtoon-style large rank number const colors = rank === 1 ? "text-yellow-400" : rank === 2 ? "text-slate-300" : rank === 3 ? "text-amber-600" : "text-white/70"; return ( {rank} ); } export function TrendingCarousel({ manga }: { manga: TrendingManga[] }) { const scrollRef = useRef(null); const [canScrollLeft, setCanScrollLeft] = useState(false); const [canScrollRight, setCanScrollRight] = useState(true); const checkScroll = useCallback(() => { const el = scrollRef.current; if (!el) return; setCanScrollLeft(el.scrollLeft > 4); setCanScrollRight(el.scrollLeft < el.scrollWidth - el.clientWidth - 4); }, []); useEffect(() => { const el = scrollRef.current; if (!el) return; checkScroll(); el.addEventListener("scroll", checkScroll, { passive: true }); window.addEventListener("resize", checkScroll); return () => { el.removeEventListener("scroll", checkScroll); window.removeEventListener("resize", checkScroll); }; }, [checkScroll]); function scroll(direction: "left" | "right") { const el = scrollRef.current; if (!el) return; const amount = el.clientWidth * 0.8; el.scrollBy({ left: direction === "left" ? -amount : amount, behavior: "smooth", }); } if (manga.length === 0) return null; return (
{/* Section header */}

Trending Now

{/* Desktop carousel arrows */}
{/* Carousel track */}
{manga.map((m, i) => (
{m.title} {/* Gradient overlay */}
{/* Rank number - bottom left, Webtoon style */}

{m.title}

{m.genre}

))}
{/* Mobile edge fades */} {canScrollRight && (
)}
); }