"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 */} scroll("left")} disabled={!canScrollLeft} className="w-8 h-8 flex items-center justify-center rounded-full bg-surface border border-border hover:bg-surface-hover disabled:opacity-25 disabled:cursor-default transition-all" aria-label="Previous" > scroll("right")} disabled={!canScrollRight} className="w-8 h-8 flex items-center justify-center rounded-full bg-surface border border-border hover:bg-surface-hover disabled:opacity-25 disabled:cursor-default transition-all" aria-label="Next" > {/* Carousel track */} {manga.map((m, i) => ( {/* Gradient overlay */} {/* Rank number - bottom left, Webtoon style */} {m.title} {m.genre} ))} {/* Mobile edge fades */} {canScrollRight && ( )} ); }
{m.genre}