import React, { useState, useCallback, useMemo, useRef, type ReactNode } from "react"; import { Box, type AlertColor } from "@mui/material"; import { NotificationContext } from "contexts/NotificationContext"; import NotificationItem from "contexts/NotificationItem"; import type { Notification } from "contexts/Notification"; export function NotificationProvider({ children }: { children: ReactNode }): React.JSX.Element { const nextId = useRef(0); const [notifications, setNotifications] = useState([]); const addNotification = useCallback((title: string, message: string, severity: AlertColor) => { const id = nextId.current++; setNotifications((prev) => [...prev, { id, title, message, severity }]); }, []); const removeNotification = useCallback((id: number) => { setNotifications((prev) => prev.filter((n) => n.id !== id)); }, []); const showSuccess = useCallback( (title: string, message: string) => addNotification(title, message, "success"), [addNotification], ); const showError = useCallback( (title: string, message: string) => addNotification(title, message, "error"), [addNotification], ); const value = useMemo(() => ({ showSuccess, showError }), [showSuccess, showError]); return ( {children} theme.zIndex.snackbar, display: "flex", flexDirection: "column", gap: 1, maxWidth: 500, width: "100%", pointerEvents: "none", }} > {notifications.map((n) => ( ))} ); }