import { notFound } from "next/navigation" import { BookOpen, Eye, BookMarked, User, Clock, Layers } from "lucide-react" import { genres, formatViews } from "@/lib/data" import { GenreBadge } from "@/components/genre-badge" import { StarRating } from "@/components/star-rating" import { ChapterList } from "@/components/chapter-list" import { CommentSection } from "@/components/comment-section" import { NovelDetailActions } from "./novel-detail-actions" import { prisma } from "@/lib/prisma" import connectToMongoDB from "@/lib/mongoose" import { Chapter } from "@/lib/models/chapter" export default async function NovelDetailPage({ params }: { params: Promise<{ slug: string }> }) { const { slug } = await params const novel = await prisma.novel.findUnique({ where: { slug }, include: { genres: { include: { genre: true } } } }) if (!novel) { notFound() } // Fetch chapters from MongoDB await connectToMongoDB() const chapters = await Chapter.find({ novelId: novel.id }) .sort({ number: 1 }) .select("id novelId number title createdAt views") .lean() // Convert Mongoose documents to plain objects for Server Component const formattedChapters = chapters.map(c => ({ id: c._id.toString(), novelId: c.novelId, number: c.number, title: c.title, createdAt: (c.createdAt as Date).toISOString(), views: c.views || 0, content: "" // We don't fetch content for the list })) const comments: any[] = [] // Temporarily empty until we implement comments const novelGenres = novel.genres.map(ng => ng.genre) || [] return (
{/* Novel Header */}
{/* Cover */}
{/* Info */}

{novel.title}

{novel.authorName} {novel.totalChapters} chương {formatViews(novel.views)} lượt xem {formatViews(novel.bookmarkCount)} bookmark Cập nhật: {novel.updatedAt.toLocaleDateString('vi-VN')}
{novel.status}
{novelGenres.map((g) => ( ))}
{/* Description */}

Giới Thiệu

{novel.description}

{/* Chapter list */}

Danh Sách Chương

{/* Comments */}
) }