'use client' import Link from 'next/link' import { useState } from 'react' import { Bell } from 'lucide-react' import { Button } from '@/components/ui/button' import { Popover, PopoverContent, PopoverTrigger } from '@/components/ui/popover' import { useNotifications } from '@/contexts/notification-context' import { cn } from '@/lib/utils' import type { NotificationResponse, NotificationSeverity } from '@/types/notifications' const SEVERITY_DOT: Record = { Info: 'bg-sky-500', Success: 'bg-emerald-500', Warning: 'bg-amber-500', Critical: 'bg-red-500', } export function timeAgo(iso: string): string { const seconds = Math.max(0, Math.floor((Date.now() - new Date(iso).getTime()) / 1000)) if (seconds < 60) return 'just now' const minutes = Math.floor(seconds / 60) if (minutes < 60) return `${minutes}m ago` const hours = Math.floor(minutes / 60) if (hours < 24) return `${hours}h ago` const days = Math.floor(hours / 24) if (days < 7) return `${days}d ago` return new Date(iso).toLocaleDateString() } export function NotificationRow({ notification: n, onOpen, }: { notification: NotificationResponse onOpen: (n: NotificationResponse) => void }) { return ( ) } export function NotificationBell() { const { recent, unreadCount, open, markAllRead } = useNotifications() const [isOpen, setIsOpen] = useState(false) return ( 0 ? `Notifications (${unreadCount} unread)` : 'Notifications'} /> } > {unreadCount > 0 && ( {unreadCount > 99 ? '99+' : unreadCount} )}
Notifications
{recent.length === 0 ? (

You're all caught up.

) : ( recent.map(n => ( { setIsOpen(false); void open(item) }} /> )) )}
setIsOpen(false)} className="block rounded-xl px-3 py-2 text-center text-sm text-muted-foreground transition-colors hover:bg-muted hover:text-foreground" > View all
) }