import { FC, useState } from "react"; import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, AlertDialogTrigger, } from "./alert-dialog"; export const Alert: FC<{ title?: string; type: string; onClick?: (event?: any) => Promise | any; children?: any; className?: string; content?: any; msg?: any; mode?: "auto" | "manual"; open?: boolean; onOpenChange?: (event: boolean) => void; hiddenFooter?: boolean; }> = ({ title = " Are you certain you want to continue?", type, onClick, children, className, content, msg, mode, open, onOpenChange, hiddenFooter = false, }) => { const [isOpen, setIsOpen] = useState(false); const message: any = { save: "Your data will be saved securely. You can update it at any time if needed.", delete: "This action cannot be undone. This will permanently remove your data from our servers.", }; const param = mode === "manual" ? { open: open, onOpenChange: onOpenChange, } : { open: isOpen, onOpenChange: (e: boolean) => { setIsOpen(e); }, }; return ( <> {mode === "manual" ? ( <> ) : ( {children} )} {content ? ( content ) : ( <> {title} {msg || message?.[type]} {!hiddenFooter ? ( <> { setIsOpen(false); }} > No { if (typeof onClick === "function") { await onClick(e); } setIsOpen(false); }} > Yes ) : ( <> )} )} ); };