import { useEffect, useRef, useState } from 'react' import { Bell, X } from 'lucide-react' import { documentsApi, type ApiNotification } from '../../lib/api' interface NotificationBellProps { compact?: boolean } export default function NotificationBell({ compact = false }: NotificationBellProps) { const [notifications, setNotifications] = useState([]) const [open, setOpen] = useState(false) const rootRef = useRef(null) useEffect(() => { void documentsApi.listNotifications().then(setNotifications).catch(() => setNotifications([])) }, []) useEffect(() => { function closeOnOutside(event: MouseEvent) { if (rootRef.current && !rootRef.current.contains(event.target as Node)) setOpen(false) } document.addEventListener('mousedown', closeOnOutside) return () => document.removeEventListener('mousedown', closeOnOutside) }, []) function toggle() { const nextOpen = !open setOpen(nextOpen) if (nextOpen) { void documentsApi.markNotificationsRead().then(() => { setNotifications((items) => items.map((item) => ({ ...item, read: true }))) }) } } return (
{open && (

Notifications

{notifications.length === 0 ? (

You’re all caught up.

) : ( notifications.slice(0, 8).map((notification) => (

{notification.message}

)) )}
)}
) }