{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "notifications-popover",
  "title": "Notifications Popover",
  "type": "registry:block",
  "files": [
    {
      "path": "packages/registry-react/blocks/notifications-popover/NotificationsPopover.tsx",
      "content": "'use client'\n\nimport * as React from 'react'\nimport {\n  UserPlus,\n  Calendar,\n  CreditCard,\n  FileText,\n  GraduationCap,\n  Target,\n  X,\n  BellOff,\n  Archive,\n  type LucideIcon,\n} from 'lucide-react'\nimport { Button } from '@/components/ui/button'\nimport { Badge } from '@/components/ui/badge'\nimport { Popover, PopoverContent, PopoverTrigger } from '@/components/ui/popover'\n\ntype NotificationCategory = 'hr' | 'payroll' | 'timeoff' | 'performance' | 'training' | 'system'\n\ninterface Notification {\n  id: string\n  title: string\n  body: string\n  category: NotificationCategory\n  timestamp: Date\n  read: boolean\n  actionUrl?: string\n  actor?: string\n}\n\nconst categoryConfig: Record<NotificationCategory, { icon: LucideIcon; accent: string; bg: string }> = {\n  hr: {\n    icon: UserPlus,\n    accent: 'bg-success',\n    bg: 'bg-success/10 text-success',\n  },\n  payroll: {\n    icon: CreditCard,\n    accent: 'bg-info',\n    bg: 'bg-info/10 text-info',\n  },\n  timeoff: {\n    icon: Calendar,\n    accent: 'bg-chart-3',\n    bg: 'bg-chart-3/10 text-chart-3',\n  },\n  performance: {\n    icon: Target,\n    accent: 'bg-warning',\n    bg: 'bg-warning/10 text-warning',\n  },\n  training: {\n    icon: GraduationCap,\n    accent: 'bg-primary',\n    bg: 'bg-primary/10 text-primary',\n  },\n  system: {\n    icon: FileText,\n    accent: 'bg-muted-foreground',\n    bg: 'bg-muted text-muted-foreground',\n  },\n}\n\nconst now = new Date()\n\nconst initialNotifications: Notification[] = [\n  {\n    id: '1',\n    title: 'Time off approved',\n    body: 'Your annual leave request for Mar 15-18 has been approved by Sarah Connor.',\n    category: 'timeoff',\n    timestamp: new Date(now.getTime() - 12 * 60 * 1000),\n    read: false,\n    actor: 'Sarah Connor',\n  },\n  {\n    id: '2',\n    title: 'New employee onboarded',\n    body: 'Marcus Rivera has joined the Engineering team as Senior Developer.',\n    category: 'hr',\n    timestamp: new Date(now.getTime() - 45 * 60 * 1000),\n    read: false,\n    actor: 'Marcus Rivera',\n  },\n  {\n    id: '3',\n    title: 'Performance review due',\n    body: 'Annual performance review for 3 direct reports is due by end of this week.',\n    category: 'performance',\n    timestamp: new Date(now.getTime() - 2 * 60 * 60 * 1000),\n    read: false,\n  },\n  {\n    id: '4',\n    title: 'Payroll processed',\n    body: 'March 2026 payroll has been processed successfully. 103 employees paid.',\n    category: 'payroll',\n    timestamp: new Date(now.getTime() - 5 * 60 * 60 * 1000),\n    read: true,\n  },\n  {\n    id: '5',\n    title: 'Training enrollment open',\n    body: 'New course available: \"Leadership Fundamentals Q2\". Enroll before Mar 20.',\n    category: 'training',\n    timestamp: new Date(now.getTime() - 8 * 60 * 60 * 1000),\n    read: true,\n  },\n  {\n    id: '6',\n    title: 'Document requires signature',\n    body: 'Updated Employee Handbook 2026 needs your acknowledgement.',\n    category: 'system',\n    timestamp: new Date(now.getTime() - 26 * 60 * 60 * 1000),\n    read: true,\n    actionUrl: '/documents',\n  },\n  {\n    id: '7',\n    title: 'Time off request pending',\n    body: 'Alice Johnson requested sick leave for Mar 12. Awaiting your approval.',\n    category: 'timeoff',\n    timestamp: new Date(now.getTime() - 28 * 60 * 60 * 1000),\n    read: true,\n    actor: 'Alice Johnson',\n  },\n  {\n    id: '8',\n    title: 'Benefits enrollment closing',\n    body: \"Open enrollment period ends Mar 31. 12 employees haven't enrolled yet.\",\n    category: 'hr',\n    timestamp: new Date(now.getTime() - 48 * 60 * 60 * 1000),\n    read: true,\n  },\n]\n\nconst todayStart = new Date(now.getFullYear(), now.getMonth(), now.getDate())\n\nfunction formatTime(date: Date): string {\n  const diffMs = now.getTime() - date.getTime()\n  const diffMin = Math.floor(diffMs / 60000)\n  if (diffMin < 1) return 'Just now'\n  if (diffMin < 60) return `${diffMin}m ago`\n  const diffHrs = Math.floor(diffMin / 60)\n  if (diffHrs < 24) return `${diffHrs}h ago`\n  const diffDays = Math.floor(diffHrs / 24)\n  if (diffDays === 1) return 'Yesterday'\n  return `${diffDays}d ago`\n}\n\nconst STYLE_ID = 'notifications-popover-styles'\nconst STYLE_CONTENT = `\n.notification-panel {\n  --scrollbar-size: 4px;\n}\n.notification-scroll::-webkit-scrollbar {\n  width: var(--scrollbar-size);\n}\n.notification-scroll::-webkit-scrollbar-track {\n  background: transparent;\n}\n.notification-scroll::-webkit-scrollbar-thumb {\n  background: var(--border);\n  border-radius: 2px;\n}\n.notification-item {\n  cursor: pointer;\n  transition: background-color 0.15s ease;\n  animation: notif-slide-in 0.25s ease both;\n}\n.notification-item:hover {\n  background-color: var(--muted);\n}\n@keyframes notif-slide-in {\n  from {\n    opacity: 0;\n    transform: translateY(4px);\n  }\n  to {\n    opacity: 1;\n    transform: translateY(0);\n  }\n}\n.notification-scroll {\n  position: relative;\n}\n.notification-scroll::after {\n  content: '';\n  position: sticky;\n  bottom: 0;\n  left: 0;\n  right: 0;\n  display: block;\n  height: 24px;\n  margin-top: -24px;\n  background: linear-gradient(to bottom, transparent, var(--popover));\n  pointer-events: none;\n}\n`\n\nexport interface NotificationsPopoverProps {\n  /** Custom trigger. Receives the live unread count. */\n  trigger?: (ctx: { unreadCount: number }) => React.ReactNode\n}\n\nexport function NotificationsPopover({ trigger }: NotificationsPopoverProps) {\n  // Inject scoped styles once.\n  React.useEffect(() => {\n    if (typeof document === 'undefined') return\n    if (document.getElementById(STYLE_ID)) return\n    const el = document.createElement('style')\n    el.id = STYLE_ID\n    el.textContent = STYLE_CONTENT\n    document.head.appendChild(el)\n  }, [])\n\n  const [notifications, setNotifications] = React.useState<Notification[]>(initialNotifications)\n  const [activeFilter, setActiveFilter] = React.useState<'all' | 'unread'>('all')\n  const [isOpen, setIsOpen] = React.useState(false)\n\n  const unreadCount = React.useMemo(() => notifications.filter((n) => !n.read).length, [notifications])\n\n  const filteredNotifications = React.useMemo(() => {\n    if (activeFilter === 'unread') {\n      return notifications.filter((n) => !n.read)\n    }\n    return notifications\n  }, [notifications, activeFilter])\n\n  const groupedNotifications = React.useMemo(() => {\n    const today = filteredNotifications.filter((n) => n.timestamp >= todayStart)\n    const earlier = filteredNotifications.filter((n) => n.timestamp < todayStart)\n    return { today, earlier }\n  }, [filteredNotifications])\n\n  function markAsRead(id: string) {\n    setNotifications((prev) => prev.map((n) => (n.id === id ? { ...n, read: true } : n)))\n  }\n\n  function markAllRead() {\n    setNotifications((prev) => prev.map((n) => ({ ...n, read: true })))\n  }\n\n  function dismissNotification(id: string) {\n    setNotifications((prev) => prev.filter((n) => n.id !== id))\n  }\n\n  function renderItem(n: Notification, animationDelay: number) {\n    const Icon = categoryConfig[n.category].icon\n    return (\n      <div\n        key={n.id}\n        className=\"notification-item group relative\"\n        style={{ animationDelay: `${animationDelay}ms` }}\n        onClick={() => markAsRead(n.id)}\n      >\n        <div\n          className={[\n            'absolute top-2 bottom-2 left-0 w-[3px] rounded-r-full transition-opacity',\n            !n.read ? categoryConfig[n.category].accent : 'opacity-0',\n          ].join(' ')}\n        />\n\n        <div className=\"flex gap-3 px-4 py-3\">\n          <div\n            className={[\n              'mt-0.5 flex size-8 shrink-0 items-center justify-center rounded-lg',\n              categoryConfig[n.category].bg,\n            ].join(' ')}\n          >\n            <Icon className=\"size-4\" />\n          </div>\n\n          <div className=\"min-w-0 flex-1\">\n            <div className=\"flex items-start justify-between gap-2\">\n              <p className={['text-[13px] leading-snug', !n.read ? 'font-semibold' : 'font-medium'].join(' ')}>\n                {n.title}\n              </p>\n              <div className=\"flex shrink-0 items-center gap-1.5\">\n                <span className=\"text-muted-foreground text-[10px] whitespace-nowrap tabular-nums\">\n                  {formatTime(n.timestamp)}\n                </span>\n                {!n.read ? <span className=\"bg-primary size-1.5 shrink-0 rounded-full\" /> : null}\n              </div>\n            </div>\n            <p className=\"text-muted-foreground mt-0.5 line-clamp-2 text-xs leading-relaxed\">{n.body}</p>\n          </div>\n\n          <button\n            className=\"text-muted-foreground hover:text-foreground mt-0.5 shrink-0 opacity-0 transition-opacity group-hover:opacity-100\"\n            title=\"Dismiss\"\n            onClick={(e) => {\n              e.stopPropagation()\n              dismissNotification(n.id)\n            }}\n          >\n            <X className=\"size-3.5\" />\n          </button>\n        </div>\n      </div>\n    )\n  }\n\n  return (\n    <Popover open={isOpen} onOpenChange={setIsOpen}>\n      <PopoverTrigger asChild>{trigger ? trigger({ unreadCount }) : <span />}</PopoverTrigger>\n      <PopoverContent\n        align=\"end\"\n        sideOffset={8}\n        className=\"notification-panel w-[380px] overflow-hidden rounded-lg border p-0 shadow-xl\"\n      >\n        <div className=\"flex items-center justify-between px-4 pt-4 pb-3\">\n          <div className=\"flex items-center gap-2.5\">\n            <h3 className=\"text-sm font-semibold tracking-tight\">Notifications</h3>\n            {unreadCount > 0 ? (\n              <Badge className=\"bg-primary/15 text-primary hover:bg-primary/15 h-5 rounded-full px-1.5 text-[10px] font-bold tabular-nums\">\n                {unreadCount}\n              </Badge>\n            ) : null}\n          </div>\n          {unreadCount > 0 ? (\n            <Button\n              variant=\"ghost\"\n              size=\"sm\"\n              className=\"text-muted-foreground hover:text-foreground -mr-1 h-7 px-2 text-xs\"\n              onClick={markAllRead}\n            >\n              Mark all read\n            </Button>\n          ) : null}\n        </div>\n\n        <div className=\"border-b px-4\">\n          <div className=\"flex gap-0\">\n            <button\n              className={[\n                'relative px-3 pb-2.5 text-xs font-medium transition-colors',\n                activeFilter === 'all' ? 'text-foreground' : 'text-muted-foreground hover:text-foreground',\n              ].join(' ')}\n              onClick={() => setActiveFilter('all')}\n            >\n              All\n              {activeFilter === 'all' ? (\n                <span className=\"bg-primary absolute right-0 bottom-0 left-0 h-[2px] rounded-t-full\" />\n              ) : null}\n            </button>\n            <button\n              className={[\n                'relative px-3 pb-2.5 text-xs font-medium transition-colors',\n                activeFilter === 'unread' ? 'text-foreground' : 'text-muted-foreground hover:text-foreground',\n              ].join(' ')}\n              onClick={() => setActiveFilter('unread')}\n            >\n              Unread\n              {activeFilter === 'unread' ? (\n                <span className=\"bg-primary absolute right-0 bottom-0 left-0 h-[2px] rounded-t-full\" />\n              ) : null}\n            </button>\n          </div>\n        </div>\n\n        <div className=\"notification-scroll max-h-[420px] overflow-y-auto\">\n          {filteredNotifications.length === 0 ? (\n            <div className=\"flex flex-col items-center justify-center py-14 text-center\">\n              <div className=\"bg-muted mb-3 rounded-full p-3\">\n                <BellOff className=\"text-muted-foreground size-5\" />\n              </div>\n              <p className=\"text-sm font-medium\">All caught up</p>\n              <p className=\"text-muted-foreground mt-0.5 text-xs\">\n                No {activeFilter === 'unread' ? 'unread ' : ''}notifications\n              </p>\n            </div>\n          ) : (\n            <>\n              {groupedNotifications.today.length > 0 ? (\n                <>\n                  <div className=\"px-4 pt-3 pb-1\">\n                    <span className=\"text-muted-foreground text-[10px] font-semibold tracking-widest uppercase\">\n                      Today\n                    </span>\n                  </div>\n                  {groupedNotifications.today.map((n, index) => renderItem(n, index * 30))}\n                </>\n              ) : null}\n\n              {groupedNotifications.earlier.length > 0 ? (\n                <>\n                  <div className=\"px-4 pt-3 pb-1\">\n                    <span className=\"text-muted-foreground text-[10px] font-semibold tracking-widest uppercase\">\n                      Earlier\n                    </span>\n                  </div>\n                  {groupedNotifications.earlier.map((n, index) =>\n                    renderItem(n, (groupedNotifications.today.length + index) * 30),\n                  )}\n                </>\n              ) : null}\n            </>\n          )}\n        </div>\n\n        <div className=\"border-t px-4 py-2.5\">\n          <a\n            href=\"#\"\n            className=\"text-muted-foreground hover:text-foreground flex items-center justify-center gap-1.5 text-xs transition-colors\"\n            onClick={() => setIsOpen(false)}\n          >\n            <Archive className=\"size-3\" />\n            View all notifications\n          </a>\n        </div>\n      </PopoverContent>\n    </Popover>\n  )\n}\n",
      "type": "registry:block",
      "target": "~/components/blocks/NotificationsPopover.tsx"
    }
  ],
  "dependencies": [
    "lucide-react"
  ],
  "devDependencies": [],
  "registryDependencies": [
    "https://uipkge.dev/r/react/button.json",
    "https://uipkge.dev/r/react/badge.json",
    "https://uipkge.dev/r/react/popover.json"
  ],
  "description": "Header-grade notifications panel. Slot-trigger Popover the consumer wraps around their own Bell button. Filter tabs (All/Unread), Today/Earlier groups, category-coloured accent bars, hover-dismiss, mark-all-read, slide-in animation. Slot receives `unreadCount` so the trigger can show a badge.",
  "categories": [
    "dashboard",
    "overlay"
  ]
}