import * as React from "react" import { BellIcon } from "lucide-react" import { Button } from "@/components/ui/button" import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover" import { cn } from "@/lib/utils" export type NotificationItem = { id: string title: React.ReactNode description?: React.ReactNode time?: React.ReactNode read?: boolean group?: React.ReactNode } export type NotificationCenterProps = React.ComponentProps<"div"> & { notifications: NotificationItem[] onMarkAllRead?: () => void onClearAll?: () => void onNotificationClick?: (notification: NotificationItem) => void emptyLabel?: React.ReactNode title?: React.ReactNode } function NotificationCenter({ notifications, onMarkAllRead, onClearAll, onNotificationClick, emptyLabel = "No new notifications", title = "Notifications", className, ...props }: NotificationCenterProps) { const unreadCount = notifications.filter((n) => !n.read).length const groupedNotifications = notifications.reduce>((accumulator, notification) => { const key = String(notification.group ?? "Recent") accumulator[key] = [...(accumulator[key] ?? []), notification] return accumulator }, {}) return (

{title}

{unreadCount > 0 ? `${unreadCount} unread update${unreadCount > 1 ? "s" : ""}` : "You're all caught up"}
{unreadCount > 0 && onMarkAllRead ? ( ) : null} {notifications.length > 0 && onClearAll ? ( ) : null}
{notifications.length === 0 ? (
{emptyLabel}
) : (
{Object.entries(groupedNotifications).map(([group, groupItems]) => (
{group}
{groupItems.map((notification) => ( ))}
))}
)}
) } export { NotificationCenter }