import { Button } from "@components/UI/Button.tsx"; import { Dialog, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, } from "@components/UI/Dialog.tsx"; import { Separator } from "@components/UI/Separator.tsx"; import type { ReactNode } from "react"; import { useTranslation } from "react-i18next"; export type DialogVariant = "default" | "destructive"; export type DialogType = "confirm" | "alert" | "info" | "custom"; export interface DialogWrapperProps { open: boolean; onOpenChange: (open: boolean) => void; title: string; description?: string; type?: DialogType; icon?: ReactNode; children?: ReactNode; showFooter?: boolean; confirmText?: string; cancelText?: string; dismissText?: string; variant?: DialogVariant; confirmIcon?: ReactNode; customFooter?: ReactNode; onConfirm?: () => void | Promise; onCancel?: () => void; onDismiss?: () => void; } export const DialogWrapper = ({ open, onOpenChange, title, description, type = "custom", icon, children, showFooter = true, confirmText, cancelText, dismissText, variant = "default", confirmIcon, customFooter, onConfirm, onCancel, onDismiss, }: DialogWrapperProps) => { const { t } = useTranslation("dialog"); const handleClose = () => { onOpenChange(false); }; const handleConfirm = async () => { if (onConfirm) { await onConfirm(); } handleClose(); }; const handleCancel = () => { if (onCancel) { onCancel(); } handleClose(); }; const handleDismiss = () => { if (onDismiss) { onDismiss(); } handleClose(); }; const renderFooter = () => { if (!showFooter) { return null; } if (customFooter) { return {customFooter}; } switch (type) { case "confirm": return ( ); case "alert": case "info": return ( ); default: return null; } }; return ( {icon && icon} {title} {type !== "custom" && } {description && {description}} {children} {renderFooter()} ); };