import { prisma } from "@/lib/db";
import { TrendingCarousel } from "@/components/TrendingCarousel";
import { GenreTabs } from "@/components/GenreTabs";

export const dynamic = "force-dynamic";

export default async function Home() {
  const manga = await prisma.manga.findMany({
    where: { status: "PUBLISHED" },
    orderBy: { updatedAt: "desc" },
    include: { _count: { select: { chapters: true } } },
  });

  // Top 10 for trending
  const trending = manga.slice(0, 10);

  // Extract unique genres
  const genres = [...new Set(manga.map((m) => m.genre))].sort();

  return (
    <div className="max-w-6xl mx-auto px-4 py-5 space-y-8">
      {/* Trending section — Webtoon-style ranked carousel */}
      <TrendingCarousel manga={trending} />

      {/* Genre browsing section — horizontal tabs + filtered grid */}
      <GenreTabs manga={manga} genres={genres} />
    </div>
  );
}
