import React, { createContext, useContext, useState, ReactNode } from 'react'; import { AlertTriangle, CheckCircle, Info, XCircle } from 'lucide-react'; type DialogType = 'alert' | 'confirm' | 'success' | 'error' | 'warning' | 'info'; interface DialogOptions { title: string; message: string; type?: DialogType; confirmLabel?: string; cancelLabel?: string; onConfirm?: () => void; onCancel?: () => void; } interface DialogContextType { showAlert: (title: string, message: string, type?: DialogType) => void; showConfirm: (title: string, message: string, onConfirm: () => void, type?: DialogType) => void; } const DialogContext = createContext(undefined); export const useDialog = () => { const context = useContext(DialogContext); if (!context) { throw new Error('useDialog must be used within a DialogProvider'); } return context; }; export const DialogProvider: React.FC<{ children: ReactNode }> = ({ children }) => { const [isOpen, setIsOpen] = useState(false); const [options, setOptions] = useState(null); const [isClosing, setIsClosing] = useState(false); const closeDialog = () => { setIsClosing(true); setTimeout(() => { setIsOpen(false); setOptions(null); setIsClosing(false); }, 400); }; const showAlert = (title: string, message: string, type: DialogType = 'info') => { setOptions({ title, message, type, confirmLabel: 'OK' }); setIsOpen(true); }; const showConfirm = (title: string, message: string, onConfirm: () => void, type: DialogType = 'warning') => { setOptions({ title, message, type, confirmLabel: 'Confirmar', cancelLabel: 'Cancelar', onConfirm: () => { onConfirm(); closeDialog(); }, onCancel: closeDialog }); setIsOpen(true); }; const getIcon = (type?: DialogType) => { switch (type) { case 'success': return ; case 'error': return ; case 'warning': return ; case 'alert': return ; default: return ; } }; const getIconBg = (type?: DialogType) => { switch (type) { case 'success': return 'bg-emerald-100'; case 'error': return 'bg-red-100'; case 'warning': return 'bg-amber-100'; case 'alert': return 'bg-red-100'; default: return 'bg-indigo-100'; } }; return ( {children} {isOpen && options && (
{getIcon(options.type)}

{options.title}

{options.message}

{options.cancelLabel && ( )}
)}
); };