import React, { createContext, useContext, useState, ReactNode } from 'react'; interface AlertConfig { type: 'success' | 'error' | 'warning' | 'info'; title: string; message: string; } interface AlertContextType { showAlert: (config: AlertConfig) => void; } const AlertContext = createContext(undefined); export const useAlert = () => { const context = useContext(AlertContext); if (!context) { throw new Error('useAlert must be used within AlertProvider'); } return context; }; interface AlertProviderProps { children: ReactNode; } export const AlertProvider: React.FC = ({ children }) => { const [alertConfig, setAlertConfig] = useState<(AlertConfig & { isOpen: boolean }) | null>(null); const showAlert = (config: AlertConfig) => { setAlertConfig({ ...config, isOpen: true }); }; const closeAlert = () => { setAlertConfig(null); }; return ( {children} {alertConfig && (
{/* Backdrop */}
{/* Dialog */}
{/* Icon and Title */}
{getIcon(alertConfig.type)}

{alertConfig.title}

{/* Message */}

{alertConfig.message}

{/* Button */}
)} ); }; const getIcon = (type: 'success' | 'error' | 'warning' | 'info') => { const icons = { success: ( ), error: ( ), warning: ( ), info: ( ), }; return icons[type]; }; const getBorderColor = (type: 'success' | 'error' | 'warning' | 'info') => { const colors = { success: 'border-green-500', error: 'border-red-500', warning: 'border-amber-500', info: 'border-blue-500', }; return colors[type]; };