import { AnimatePresence, motion } from "framer-motion" import { CircleCheck, AlertTriangle, Info, CircleX, X } from "lucide-react" import { useEffect, useState, useRef } from "react" import { ToastProps } from "./ToastProps.js" const icons = { success: CircleCheck, error: CircleX, warning: AlertTriangle, info: Info } const colors = { success: 'text-success', error: 'text-destructive', warning: 'text-attention', info: 'text-info' } interface NotificationPanelProps { data: ToastProps onClose: () => void } export function NotificationPanel({ data, onClose }: NotificationPanelProps) { const [show, setShow] = useState(true) const timeoutRef = useRef(null) const resetTimeout = () => { if (timeoutRef.current) { globalThis.clearTimeout(timeoutRef.current) } if (data.duration) { timeoutRef.current = setTimeout(() => setShow(false), data.duration) } } const clearCurrentTimeout = () => { if (timeoutRef.current) { globalThis.clearTimeout(timeoutRef.current) timeoutRef.current = null } } useEffect(() => { resetTimeout() return clearCurrentTimeout }, [data.duration]) const Icon = icons[data.status] || Info; const color = colors[data.status] || 'text-info'; // Global notification live region, render this permanently at the end of the document return (
{/* Notification panel, dynamically insert this into the live region when it needs to be displayed */} {show && (

{data.title}

{data.description && (

{data.description}

)}
)}
) }