"use client" import { Card, CardContent } from "@/shared/components/ui/card" import { Badge } from "@/shared/components/ui/badge" import { Button } from "@/shared/components/ui/button" import { Tag, Trash2 } from "lucide-react" import { KnowledgePoint } from "../types" import { CreateKnowledgePointDialog } from "./create-knowledge-point-dialog" import { deleteKnowledgePointAction } from "../actions" import { toast } from "sonner" import { ScrollArea } from "@/shared/components/ui/scroll-area" interface KnowledgePointPanelProps { knowledgePoints: KnowledgePoint[] selectedChapterId: string | null textbookId: string } export function KnowledgePointPanel({ knowledgePoints, selectedChapterId, textbookId }: KnowledgePointPanelProps) { const handleDelete = async (id: string) => { if (!confirm("Are you sure you want to delete this knowledge point?")) return const result = await deleteKnowledgePointAction(id, textbookId) if (result.success) { toast.success(result.message) } else { toast.error(result.message) } } // Filter KPs for the selected chapter const chapterKPs = selectedChapterId ? knowledgePoints.filter(kp => kp.chapterId === selectedChapterId) : [] return (

Knowledge Points

{selectedChapterId && ( )}
{selectedChapterId ? ( chapterKPs.length > 0 ? (
{chapterKPs.map((kp) => (
{kp.name}
{kp.description && (

{kp.description}

)}
))}
) : (
No knowledge points linked to this chapter yet.
) ) : (
Select a chapter to manage its knowledge points.
)}
) }