import React, { useState, useEffect } from 'react' import ReactDOM from 'react-dom' import { useNavigate } from 'react-router-dom' import { Bell, Trash2, CheckCheck } from 'lucide-react' import { useTranslation } from '../../i18n' import { useInAppNotificationStore } from '../../store/inAppNotificationStore.ts' import { useSettingsStore } from '../../store/settingsStore' import { useAuthStore } from '../../store/authStore' import InAppNotificationItem from '../Notifications/InAppNotificationItem.tsx' export default function InAppNotificationBell(): React.ReactElement { const { t } = useTranslation() const navigate = useNavigate() const { settings } = useSettingsStore() const darkMode = settings.dark_mode const dark = darkMode === true || darkMode === 'dark' || (darkMode === 'auto' && window.matchMedia('(prefers-color-scheme: dark)').matches) const isAuthenticated = useAuthStore(s => s.isAuthenticated) const { notifications, unreadCount, isLoading, fetchNotifications, fetchUnreadCount, markAllRead, deleteAll } = useInAppNotificationStore() const [open, setOpen] = useState(false) useEffect(() => { if (isAuthenticated) { fetchUnreadCount() } }, [isAuthenticated]) const handleOpen = () => { if (!open) { fetchNotifications(true) } setOpen(v => !v) } const handleShowAll = () => { setOpen(false) navigate('/notifications') } const displayCount = unreadCount > 99 ? '99+' : unreadCount return (
{open && ReactDOM.createPortal( <>
setOpen(false)} />
{/* Header */}
{t('notifications.title')} {unreadCount > 0 && ( {unreadCount} )}
{unreadCount > 0 && ( )} {notifications.length > 0 && ( )}
{/* Notification list */}
{isLoading && notifications.length === 0 ? (
) : notifications.length === 0 ? (

{t('notifications.empty')}

{t('notifications.emptyDescription')}

) : ( notifications.slice(0, 10).map(n => ( setOpen(false)} /> )) )}
{/* Footer */}
, document.body )}
) }