import { createContext, ReactNode, useContext } from 'react'; import { Toaster } from '@/Components/ui/sonner'; import { toast } from 'sonner'; type NotificationContext = { notify: ( msg: string ) => void; }; export const NotificationsContext = createContext< NotificationContext | undefined >( undefined ); export const useNotifications = () => { const notifications = useContext( NotificationsContext ); if ( notifications === undefined ) { throw new Error( 'useNotifications must be used within a NotificationsContext' ); } return notifications; }; type NotificationType = 'error' | 'success' | 'info' | 'warning'; export const NotificationsProvider = ( { children }: { children: ReactNode } ) => { function notify( msg: string, type: NotificationType = 'error' ) { const title = 'AgentWP'; if ( type === 'error' ) { toast.error( title, { description: msg, } ); } else { toast.info( title, { description: msg, } ); } } return ( { children } ); };