import { useEffect, useRef } from "react"; import { useNotifications } from "../hooks/use-notifications"; import { NotificationItem } from "./notification-item"; import { Icon } from "./icon"; interface NotificationCenterProps { isMobileTerminal?: boolean; } export function NotificationCenter({ isMobileTerminal = false, }: NotificationCenterProps) { const { notifications, unreadCount, markRead, markAllRead, clearAll, dismiss, refreshList, isDropdownOpen, setIsDropdownOpen, } = useNotifications(); const dropdownRef = useRef(null); useEffect(() => { if (!isDropdownOpen) return; const handleMouseDown = (e: MouseEvent) => { if ( dropdownRef.current && !dropdownRef.current.contains(e.target as Node) ) { setIsDropdownOpen(false); } }; const handleKeyDown = (e: KeyboardEvent) => { if (e.key === "Escape") { setIsDropdownOpen(false); } }; document.addEventListener("mousedown", handleMouseDown); document.addEventListener("keydown", handleKeyDown); return () => { document.removeEventListener("mousedown", handleMouseDown); document.removeEventListener("keydown", handleKeyDown); }; }, [isDropdownOpen, setIsDropdownOpen]); useEffect(() => { if (isDropdownOpen) { void refreshList(); } }, [isDropdownOpen, refreshList]); if (isMobileTerminal) { return null; } const badgeText = unreadCount > 99 ? "99+" : String(unreadCount); return (
{isDropdownOpen && (
Notifications
    {notifications.length === 0 ? (
  • No notifications
  • ) : ( notifications.map((n) => ( )) )}
{notifications.length > 0 && (
)}
)}
); }