import { useEffect, useState } from "react"; import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, } from "@/components/ui/dialog"; import { Button } from "@/components/ui/button"; import { Checkbox } from "@/components/ui/checkbox"; import { AlertTriangle, Info } from "lucide-react"; import { useTranslation } from "react-i18next"; interface ConfirmDialogProps { isOpen: boolean; title: string; message: string; confirmText?: string; cancelText?: string; variant?: "destructive" | "info"; zIndex?: "base" | "nested" | "alert" | "top"; /** 可选勾选项:提供 label 即显示,勾选状态经 onConfirm 参数回传 */ checkboxLabel?: string; checkboxDefaultChecked?: boolean; onConfirm: (checkboxChecked: boolean) => void; onCancel: () => void; } export function ConfirmDialog({ isOpen, title, message, confirmText, cancelText, variant = "destructive", zIndex = "alert", checkboxLabel, checkboxDefaultChecked = false, onConfirm, onCancel, }: ConfirmDialogProps) { const { t } = useTranslation(); const [checkboxChecked, setCheckboxChecked] = useState( checkboxDefaultChecked, ); useEffect(() => { if (isOpen) { setCheckboxChecked(checkboxDefaultChecked); } }, [isOpen, checkboxDefaultChecked]); const IconComponent = variant === "info" ? Info : AlertTriangle; const iconClass = variant === "info" ? "h-5 w-5 text-blue-500" : "h-5 w-5 text-destructive"; return ( { if (!open) { onCancel(); } }} > {title} {message} {checkboxLabel ? ( ) : null} ); }