import { useState, useCallback } from 'react'; import { Notification, NotificationType } from '../types'; import { useNotifications } from './useNotifications'; export function useNotificationCenter() { const [isOpen, setIsOpen] = useState(false); const [filter, setFilter] = useState('all'); const [searchQuery, setSearchQuery] = useState(''); const { notifications, unreadCount, markAsRead, markAllAsRead, deleteNotification, clearAll, } = useNotifications(); const open = useCallback(() => setIsOpen(true), []); const close = useCallback(() => setIsOpen(false), []); const toggle = useCallback(() => setIsOpen(prev => !prev), []); // Filter notifications const filteredNotifications = notifications.filter(notification => { // Type filter if (filter !== 'all' && notification.type !== filter) { return false; } // Search filter if (searchQuery) { const query = searchQuery.toLowerCase(); return ( notification.title.toLowerCase().includes(query) || notification.message?.toLowerCase().includes(query) ); } return true; }); // Group notifications by date const groupedNotifications = filteredNotifications.reduce((groups, notification) => { const date = new Date(notification.createdAt); const dateKey = date.toDateString(); if (!groups[dateKey]) { groups[dateKey] = []; } groups[dateKey].push(notification); return groups; }, {} as Record); return { isOpen, open, close, toggle, notifications: filteredNotifications, groupedNotifications, unreadCount, filter, setFilter, searchQuery, setSearchQuery, markAsRead, markAllAsRead, deleteNotification, clearAll, }; }