"use client" import { use, useMemo } from "react" import Link from "next/link" import { notFound } from "next/navigation" import { ChevronLeft, ChevronRight, List } from "lucide-react" import { getNovelBySlug, getChapter, getChaptersByNovelId, getCommentsByChapterId } from "@/lib/data" import { Button } from "@/components/ui/button" import { ReadingSettings } from "@/components/reading-settings" import { CommentSection } from "@/components/comment-section" import { TTSPlayer } from "@/components/tts-player" import { ChapterReaderProgress } from "./chapter-reader-progress" export default function ChapterReaderPage({ params }: { params: Promise<{ slug: string; chapterId: string }> }) { const { slug, chapterId } = use(params) const chapterNumber = parseInt(chapterId, 10) const novel = getNovelBySlug(slug) if (!novel || isNaN(chapterNumber)) { notFound() } const chapter = getChapter(novel.id, chapterNumber) const allChapters = getChaptersByNovelId(novel.id) const maxChapter = allChapters.length if (!chapter) { notFound() } const comments = getCommentsByChapterId(chapter.id) const hasPrev = chapterNumber > 1 const hasNext = chapterNumber < maxChapter // Extract paragraphs for TTS const paragraphs = useMemo( () => chapter.content.split("\n").map((p) => p.trim()).filter(Boolean), [chapter.content] ) return (
{/* Top navigation */}
{novel.title}

Chương {chapter.number}: {chapter.title}

{/* Chapter navigation top */}
{/* Chapter content */}
{paragraphs.map((text, idx) => (

{text}

))}
{/* Chapter navigation bottom */}
{/* Save reading progress */} {/* Comments */}
{/* TTS Player */}
) }