"use client"; import { useState, useRef, useEffect } from "react"; import { Bell, CheckCheck, Trash2 } from "lucide-react"; import { AnimatePresence, motion } from "framer-motion"; import { cn } from "@/lib/utils"; import { useNotifications } from "@/hooks/useNotifications"; import { NotificationBadge } from "./NotificationBadge"; import { NotificationItem } from "./NotificationItem"; import type { NotificationCategory } from "@/lib/notifications"; type FilterCategory = "all" | NotificationCategory; const FILTER_TABS: { key: FilterCategory; label: string }[] = [ { key: "all", label: "All" }, { key: "error", label: "Errors" }, { key: "activity", label: "Activity" }, { key: "system", label: "System" }, ]; export function NotificationCenter() { const [isOpen, setIsOpen] = useState(false); const [activeFilter, setActiveFilter] = useState("all"); const containerRef = useRef(null); const { notifications, unreadCount, markRead, markAllRead, clearHistory } = useNotifications(); // Close on click outside useEffect(() => { if (!isOpen) return; const handler = (e: MouseEvent) => { if ( containerRef.current && !containerRef.current.contains(e.target as Node) ) { setIsOpen(false); } }; document.addEventListener("mousedown", handler); return () => document.removeEventListener("mousedown", handler); }, [isOpen]); // Close on Escape useEffect(() => { if (!isOpen) return; const handler = (e: KeyboardEvent) => { if (e.key === "Escape") setIsOpen(false); }; document.addEventListener("keydown", handler); return () => document.removeEventListener("keydown", handler); }, [isOpen]); const filtered = activeFilter === "all" ? notifications : notifications.filter((n) => n.category === activeFilter); return (
{/* Bell button */} {/* Panel */} {isOpen && ( {/* Header */}

Notifications

{unreadCount > 0 && ( )} {notifications.length > 0 && ( )}
{/* Filter tabs */}
{FILTER_TABS.map((tab) => { const count = tab.key === "all" ? notifications.length : notifications.filter((n) => n.category === tab.key).length; return ( ); })}
{/* Notification list */}
{filtered.length === 0 ? (

No notifications

) : (
{filtered.map((n) => ( ))}
)}
)}
); }