"use client"; import { useState } from "react"; import { IconLoader } from "@tabler/icons-react"; import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, } from "@kandev/ui/alert-dialog"; import { Checkbox } from "@kandev/ui/checkbox"; import { useSubtaskCount } from "@/hooks/use-subtask-count"; import { getCleanupSummary, getBulkCleanupSummary } from "./task-cleanup-summary"; type TaskDeleteConfirmDialogProps = { open: boolean; onOpenChange: (open: boolean) => void; taskTitle?: string; isBulkOperation?: boolean; count?: number; isDeleting?: boolean; taskId?: string; taskIds?: string[]; /** Executor type of the task being deleted (single). */ executorType?: string | null; /** Executor types of the tasks being deleted (bulk). */ executorTypes?: Array; onConfirm: (opts: { cascade: boolean }) => void; confirmTestId?: string; }; export function TaskDeleteConfirmDialog({ open, onOpenChange, taskTitle, isBulkOperation, count, isDeleting, taskId, taskIds, executorType, executorTypes, onConfirm, confirmTestId, }: TaskDeleteConfirmDialogProps) { const safeCount = count ?? 0; const label = isBulkOperation ? `task${safeCount !== 1 ? "s" : ""}` : "task"; const title = isBulkOperation ? `Delete ${safeCount} ${label}` : "Delete task"; const description = isBulkOperation ? `Are you sure you want to delete ${safeCount} ${label}? This action cannot be undone.` : `Are you sure you want to delete "${taskTitle}"? This action cannot be undone.`; const cleanup = isBulkOperation ? getBulkCleanupSummary(executorTypes ?? []) : getCleanupSummary(executorType); const [cascade, setCascade] = useState(false); const subtaskCount = useSubtaskCount(open, taskId, taskIds); const handleOpenChange = (next: boolean) => { if (!next) setCascade(false); onOpenChange(next); }; return ( e.stopPropagation()}> {title}

{description}

{cleanup.lines.map((line, i) => (

{line}

))}
{subtaskCount > 0 && ( )} Cancel { if (isDeleting) return; onConfirm({ cascade }); handleOpenChange(false); }} > {isDeleting ? : null} Delete
); }