import { useState } from 'react' import { NotificationContext, Notification } from '../context/NotificationContext' import { CheckCircleIcon, InformationCircleIcon, ExclamationTriangleIcon, } from '@heroicons/react/24/outline' const NotificationsProvider = ({ children }: { children: React.ReactNode }) => { const [notifications, setNotifications] = useState<(Notification & { id: string })[]>([]) const addNotification = (newNotif: Notification) => { const { message, type, duration = 5000 } = newNotif const id = crypto.randomUUID() setNotifications((prev) => [...prev, { id, message, type, duration }]) if (duration > 0) { setTimeout(() => { removeNotification(id) }, duration) } } const removeNotification = (id: string) => { setNotifications((prev) => prev.filter((n) => n.id !== id)) } const removeAllNotifications = () => { setNotifications([]) } const Icon = ({ type }: { type: string }) => { switch (type) { case 'error': return case 'success': return case 'info': return default: return } } return ( {children}
{notifications.map((notification) => (
removeNotification(notification.id)} >

{notification.message}

))}
) } export default NotificationsProvider