"use client" import { useState } from "react" import { ChevronRight, FileText, Folder, MoreHorizontal, Plus, Trash2 } from "lucide-react" import { toast } from "sonner" import { Chapter } from "../types" import { Collapsible, CollapsibleContent, CollapsibleTrigger, } from "@/shared/components/ui/collapsible" import { Button } from "@/shared/components/ui/button" import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuSeparator, DropdownMenuTrigger, } from "@/shared/components/ui/dropdown-menu" import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, } from "@/shared/components/ui/alert-dialog" import { cn } from "@/shared/lib/utils" import { CreateChapterDialog } from "./create-chapter-dialog" import { deleteChapterAction } from "../actions" interface ChapterItemProps { chapter: Chapter level?: number selectedId?: string onSelect: (chapter: Chapter) => void textbookId: string } function ChapterItem({ chapter, level = 0, selectedId, onSelect, textbookId }: ChapterItemProps) { const [isOpen, setIsOpen] = useState(false) const [showCreateDialog, setShowCreateDialog] = useState(false) const [showDeleteDialog, setShowDeleteDialog] = useState(false) const [isDeleting, setIsDeleting] = useState(false) const hasChildren = chapter.children && chapter.children.length > 0 const isSelected = chapter.id === selectedId const handleDelete = async () => { setIsDeleting(true) const res = await deleteChapterAction(chapter.id, textbookId) setIsDeleting(false) if (res.success) { toast.success(res.message) setShowDeleteDialog(false) } else { toast.error(res.message) } } return (