import Link from "next/link"; import { PageHeader } from "@/components/page-header"; import { notFound } from "next/navigation"; import { getBookMeta, getChapterVerses, getChapterVerseIndex } from "@/lib/api"; import { ChapterViewer } from "@/app/books/chapter-viewer"; type ChapterInfo = { number: number; title: string; totalVerses: number; }; type CantoInfo = { number: number; title: string; totalChapters: number; chapters: ChapterInfo[]; }; export default async function SbChapterPage({ params, }: { params: Promise<{ canto: string; chapter: string }>; }) { const { canto, chapter } = await params; const PAGE_SIZE = 20; const meta = await getBookMeta("sb"); if (!meta) notFound(); const cantos = (meta as unknown as { cantos: CantoInfo[] }).cantos; const cantoInfo = cantos.find((c) => c.number === parseInt(canto)); if (!cantoInfo) notFound(); const chapterInfo = cantoInfo.chapters.find( (ch) => ch.number === parseInt(chapter), ); if (!chapterInfo) notFound(); const [verseIndex, firstPage] = await Promise.all([ getChapterVerseIndex("sb", canto, parseInt(chapter)), getChapterVerses("sb", canto, parseInt(chapter), 1, PAGE_SIZE), ]); if (verseIndex.length === 0) notFound(); return (
← Canto {cantoInfo.number}: {cantoInfo.title}

Chapter {chapter}: {chapterInfo.title}

({ verse: v.verse, verseEnd: v.verseEnd ?? undefined, reference: v.reference, }))} />
); }