"use client"; import { useState } from "react"; import { Button } from "@/components/ui/button"; import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, } from "@/components/ui/dialog"; import { deleteLayoutSection } from "@/app/actions/layout-configurations"; import { useToast } from "@/hooks/use-toast"; interface DeleteSectionDialogProps { open: boolean; onOpenChange: (open: boolean) => void; section: { id: number; name: string; }; onSuccess?: () => void; } export function DeleteSectionDialog({ open, onOpenChange, section, onSuccess, }: DeleteSectionDialogProps) { const [isDeleting, setIsDeleting] = useState(false); const { toast } = useToast(); const handleDelete = async () => { setIsDeleting(true); try { const result = await deleteLayoutSection(section.id); if (result.success) { toast({ title: "Section deleted", description: `Successfully deleted section "${section.name}"`, }); onOpenChange(false); onSuccess?.(); } else { toast({ title: "Error", description: result.error || "Failed to delete section", variant: "destructive", }); } } catch { toast({ title: "Error", description: "An unexpected error occurred while deleting the section", variant: "destructive", }); } finally { setIsDeleting(false); } }; return ( Delete Section Are you sure you want to delete the section "{section.name}"? This action cannot be undone. All fields within this section will also be deleted. ); }