export const dynamic = "force-dynamic"; import type { Metadata } from "next"; import Link from "next/link"; import { redirect, notFound } from "next/navigation"; import { ChevronLeft, ChevronRight } from "lucide-react"; import { getBookMeta, getProseChapter, getChapterVerseIndex } from "@/lib/api"; import { CC_LILAS } from "@/lib/constants"; import { buildOgMeta } from "@/lib/og"; import { PageHeader } from "@/components/layout/page-header"; import { Card, CardContent } from "@/components/ui/card"; import { buttonVariants } from "@/components/ui/button"; import { FindInPage } from "@/components/layout/find-in-page"; import { MobileNav, type MobileNavGroup } from "@/components/layout/mobile-nav"; import { cn } from "@/lib/utils"; type ChapterInfo = { number: number; title: string; totalVerses: number }; type LilaInfo = { key: string; name: string; totalChapters: number; totalVerses: number; chapters: ChapterInfo[]; }; type VerseEntry = { verse: number; verseEnd?: number | null; reference: string }; export async function generateMetadata({ params, }: { params: Promise<{ lila: string; chapter: string }>; }): Promise { const { lila, chapter } = await params; const lilaName = CC_LILAS[lila] || lila; return buildOgMeta({ title: "Śrī Caitanya-caritāmṛta", detail: `${lilaName}, Chapter ${chapter}`, }); } function verseLabel(v: VerseEntry): string { return v.verseEnd ? `${v.verse}–${v.verseEnd}` : String(v.verse); } // --------------------------------------------------------------------------- // Top/bottom navigation — mirrors the verse pages' VerseNav: a Contents // toggle (mobile) listing this chapter's verses, Previous/Next (chapter), and // a "Chapter X of N" label. // --------------------------------------------------------------------------- function ChapterNav({ lila, chapters, current, chapterTitle, verseIndex, }: { lila: string; chapters: ChapterInfo[]; current: number; chapterTitle: string; verseIndex: VerseEntry[]; }) { const idx = chapters.findIndex((c) => c.number === current); const prev = idx > 0 ? chapters[idx - 1] : null; const next = idx < chapters.length - 1 ? chapters[idx + 1] : null; // The contents drawer lists the active chapter's verses (same as the // verse-page sidebar) so the reader can jump straight in. const groups: MobileNavGroup[] = [ { title: "Verses", items: verseIndex.map((v) => ({ slug: String(v.verse), label: `Verse ${verseLabel(v)}`, href: `/books/cc/${lila}/${current}/${v.verse}`, type: "verse", })), }, ]; return (
{prev ? ( Previous ) : (
)}
Chapter {current} of {chapters.length} {next ? ( Next ) : (
)}
); } export default async function CcChapterPage({ params, }: { params: Promise<{ lila: string; chapter: string }>; }) { const { lila, chapter } = await params; const chapterNum = parseInt(chapter); const [meta, summary, verseIndex] = await Promise.all([ getBookMeta("cc"), getProseChapter("cc", 0, `${lila}-${chapterNum}`), getChapterVerseIndex("cc", lila, chapterNum), ]); if (!meta) notFound(); const lilaInfo = (meta.lilas as LilaInfo[] | undefined)?.find( (l) => l.key === lila, ); if (!lilaInfo) notFound(); const chapterInfo = lilaInfo.chapters.find((ch) => ch.number === chapterNum); if (!chapterInfo) notFound(); if (verseIndex.length === 0) notFound(); const firstVerse = verseIndex[0].verse; // Chapters without a summary (e.g. Ādi 7) go straight to the verses. if (!summary || summary.paragraphs.length === 0) { redirect(`/books/cc/${lila}/${chapterNum}/${firstVerse}`); } return (
← {lilaInfo.name}

Chapter {chapterNum}: {chapterInfo.title}

{/* Desktop sidebar — verses of the active chapter (matches the verse-page sidebar) so the reader can jump to any verse. */} {/* Main — chapter summary */}
{/* Top navigation */}

Chapter Summary

{summary.paragraphs.map((paragraph, i) => (
))}
{/* Bottom navigation */}
); }