"use client" import { useState } from "react" import ReactMarkdown from "react-markdown" import remarkBreaks from "remark-breaks" import remarkGfm from "remark-gfm" import { Chapter, KnowledgePoint } from "../types" import { ChapterSidebarList } from "./chapter-sidebar-list" import { KnowledgePointPanel } from "./knowledge-point-panel" import { ScrollArea } from "@/shared/components/ui/scroll-area" import { Button } from "@/shared/components/ui/button" import { Edit2, Save } from "lucide-react" import { CreateChapterDialog } from "./create-chapter-dialog" import { updateChapterContentAction } from "../actions" import { toast } from "sonner" import { Textarea } from "@/shared/components/ui/textarea" interface TextbookContentLayoutProps { chapters: Chapter[] knowledgePoints: KnowledgePoint[] textbookId: string } export function TextbookContentLayout({ chapters, knowledgePoints, textbookId }: TextbookContentLayoutProps) { const [selectedChapter, setSelectedChapter] = useState(null) const [isEditing, setIsEditing] = useState(false) const [editContent, setEditContent] = useState("") const [isSaving, setIsSaving] = useState(false) // Sync edit content when selection changes const handleSelectChapter = (chapter: Chapter) => { setSelectedChapter(chapter) setEditContent(chapter.content || "") setIsEditing(false) } const handleSaveContent = async () => { if (!selectedChapter) return setIsSaving(true) const result = await updateChapterContentAction(selectedChapter.id, editContent, textbookId) setIsSaving(false) if (result.success) { toast.success(result.message) setIsEditing(false) setSelectedChapter((prev) => (prev ? { ...prev, content: editContent } : prev)) } else { toast.error(result.message) } } return (
{/* Left Sidebar: TOC (3 cols) */}

Chapters

{/* Middle: Content Viewer/Editor (6 cols) */}
{selectedChapter ? ( <>

{selectedChapter.title}

{isEditing ? ( <> ) : ( )}
{isEditing ? (