import Link from "next/link"; import { notFound } from "next/navigation"; import { getProseChapter, getProseChapters } from "@/lib/api"; import { PageHeader } from "@/components/page-header"; import { Card, CardContent } from "@/components/ui/card"; import { buttonVariants } from "@/components/ui/button"; import { ChevronLeft, ChevronRight } from "lucide-react"; import { cn } from "@/lib/utils"; export default async function KbChapterPage({ params, }: { params: Promise<{ volume: string; slug: string }>; }) { const { volume, slug } = await params; const vol = parseInt(volume); if (isNaN(vol) || vol < 1 || vol > 2) notFound(); const chapter = await getProseChapter("kb", vol, slug); if (!chapter) notFound(); // Fetch all chapters/segments in this volume for sidebar + prev/next const allChapters = await getProseChapters("kb", vol); const currentIdx = allChapters.findIndex((ch) => ch.slug === slug); const prev = currentIdx > 0 ? allChapters[currentIdx - 1] : null; const next = currentIdx < allChapters.length - 1 ? allChapters[currentIdx + 1] : null; const chapterLabel = chapter.type === "chapter" && chapter.chapter != null ? `Chapter ${chapter.chapter}` : null; return (
← Volume {vol}

{chapterLabel && ( {chapterLabel}: )} {chapter.title}

{/* Left sidebar — chapter index */} {/* Main content */}
{/* Top navigation */} {/* Chapter content */}
{chapter.paragraphs.map((paragraph, i) => (
))}
{/* Bottom navigation */}
); } // --------------------------------------------------------------------------- // Sidebar — chapter index // --------------------------------------------------------------------------- type SidebarChapter = { slug: string; title: string; type: string; chapter: number | null; }; function ChapterSidebar({ chapters, currentSlug, volume, }: { chapters: SidebarChapter[]; currentSlug: string; volume: number; }) { return ( ); } // --------------------------------------------------------------------------- // Prev / Next navigation // --------------------------------------------------------------------------- type NavChapter = { slug: string; title: string; type: string; chapter: number | null; }; function ChapterNav({ prev, next, volume, }: { prev: NavChapter | null; next: NavChapter | null; volume: number; }) { return (
{prev ? ( {prev.type === "chapter" && prev.chapter != null ? `Ch. ${prev.chapter}` : prev.title} Previous ) : (
)} {next ? ( {next.type === "chapter" && next.chapter != null ? `Ch. ${next.chapter}` : next.title} Next ) : (
)}
); }