{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "notification-center",
  "type": "registry:ui",
  "title": "NotificationList، NotificationCenter",
  "description": "فهرست اعلان‌ها با زبانه‌های «همه» و «خوانده‌نشده»، گروه امروز و دیروز و زمان نسبی فارسی؛ تنها یا داخل NotificationCenter",
  "dependencies": [
    "@kashi-ui/persian@^2.26.0"
  ],
  "registryDependencies": [
    "https://kashi.sepantapouya.com/r/cx.json",
    "https://kashi.sepantapouya.com/r/kashi-provider.json",
    "https://kashi.sepantapouya.com/r/popover.json"
  ],
  "files": [
    {
      "path": "registry/kashi/NotificationCenter.tsx",
      "type": "registry:ui",
      "target": "components/kashi/NotificationCenter.tsx",
      "content": "\"use client\";\n\nimport { useEffect, useRef, useState, type ReactNode } from \"react\";\nimport { formatRelative } from \"@kashi-ui/persian\";\nimport { cx } from \"./cx\";\nimport { useKashiLocale, useMessages } from \"./KashiProvider\";\nimport { faNotifications } from \"@kashi-ui/persian\";\nimport { Popover } from \"./Popover\";\n\nexport interface NotificationItem {\n  id: string;\n  title: ReactNode;\n  body?: ReactNode;\n  time: Date;\n  read?: boolean;\n  /** آواتار یا آیکون سمت شروع */\n  icon?: ReactNode;\n  tone?: \"brand\" | \"success\" | \"warning\" | \"error\";\n  /** پیوند اعلان؛ بدون آن onSelect صدا زده می‌شود */\n  href?: string;\n}\n\nexport interface NotificationListProps {\n  items: NotificationItem[];\n  /** خوانده شدن یک اعلان (با کلیک یا دکمهٔ نقطه) */\n  onRead?: (id: string) => void;\n  onReadAll?: () => void;\n  onSelect?: (item: NotificationItem) => void;\n  /** دکمهٔ تنظیمات کنار عنوان */\n  onSettings?: () => void;\n  /** پیوند «دیدن همهٔ اعلان‌ها» پایین فهرست */\n  viewAllHref?: string;\n  /** عنوان بالای فهرست @default \"اعلان‌ها\" */\n  title?: ReactNode;\n  /** لحظهٔ مقایسه برای زمان نسبی و گروه امروز و دیروز @default اکنون */\n  now?: Date;\n  className?: string;\n}\n\nconst svg = (d: string) => <svg viewBox=\"0 0 20 20\" fill=\"none\" stroke=\"currentColor\" strokeWidth={1.7} strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\"><path d={d} /></svg>;\nconst Bell = () => svg(\"M5 8a5 5 0 0 1 10 0c0 4 1.5 5.5 1.5 5.5h-13S5 12 5 8ZM8.5 16.5a1.6 1.6 0 0 0 3 0\");\nconst Gear = () => svg(\"M10 12.5a2.5 2.5 0 1 0 0-5 2.5 2.5 0 0 0 0 5ZM16 10a6 6 0 0 0-.1-1l1.6-1.3-1.5-2.6-2 .7a6 6 0 0 0-1.7-1L12 2.8H9l-.4 2a6 6 0 0 0-1.7 1l-2-.7-1.5 2.6L5 9a6 6 0 0 0 0 2l-1.6 1.3 1.5 2.6 2-.7a6 6 0 0 0 1.7 1l.4 2h3l.4-2a6 6 0 0 0 1.7-1l2 .7 1.5-2.6L15.9 11c.1-.3.1-.7.1-1Z\");\nconst CheckAll = () => svg(\"m2.5 10.5 3 3 6-7M9 13.2l.3.3 6-7\");\nconst day = (d: Date) => new Date(d.getFullYear(), d.getMonth(), d.getDate()).getTime();\n\n/** فهرست اعلان‌ها با زبانه‌های «همه» و «خوانده‌نشده»، گروه امروز و دیروز و زمان نسبی فارسی؛ تنها یا داخل NotificationCenter */\nexport function NotificationList({ items, onRead, onReadAll, onSelect, onSettings, viewAllHref, title, now, className }: NotificationListProps) {\n  const M = useMessages({ notifications: faNotifications });\n  const { locale, digits, n } = useKashiLocale();\n  const N = M.notifications;\n  const [tab, setTab] = useState<\"all\" | \"unread\">(\"all\");\n  const unread = items.filter((x) => !x.read).length;\n  const list = tab === \"unread\" ? items.filter((x) => !x.read) : items;\n  const ref = now ?? new Date();\n  const today = day(ref);\n  const groups: [string, NotificationItem[]][] = [[N.today, []], [N.yesterday, []], [N.earlier, []]];\n  for (const it of [...list].sort((a, b) => b.time.getTime() - a.time.getTime())) {\n    const d = day(it.time);\n    groups[d >= today ? 0 : d >= today - 86_400_000 ? 1 : 2][1].push(it);\n  }\n\n  return (\n    <div className={cx(\"k-notif\", className)}>\n      <div className=\"k-notif__head\">\n        <h2 className=\"k-notif__title\">{title ?? N.label}</h2>\n        {onReadAll && unread > 0 && (\n          <button type=\"button\" className=\"k-notif__link\" onClick={onReadAll}><CheckAll />{N.markAll}</button>\n        )}\n        {onSettings && <button type=\"button\" className=\"k-notif__icon\" aria-label={N.settings} onClick={onSettings}><Gear /></button>}\n      </div>\n      <div className=\"k-notif__tabs\" role=\"group\">\n        {([\"all\", \"unread\"] as const).map((t) => (\n          <button key={t} type=\"button\" className=\"k-notif__tab\" aria-pressed={tab === t} onClick={() => setTab(t)}>\n            {N[t]}\n            {t === \"unread\" && unread > 0 && <span className=\"k-notif__count\">{n(unread)}</span>}\n          </button>\n        ))}\n      </div>\n      {list.length === 0 ? (\n        <div className=\"k-notif__empty\">\n          <span className=\"k-notif__empty-icon\"><Bell /></span>\n          <p>{tab === \"unread\" ? N.emptyUnread : N.empty}</p>\n        </div>\n      ) : (\n        <div className=\"k-notif__scroll\" tabIndex={-1}>\n          {groups.filter(([, g]) => g.length).map(([name, g]) => (\n            <section key={name} className=\"k-notif__group\" aria-label={name}>\n              <h3 className=\"k-notif__group-title\">{name}</h3>\n              <ul className=\"k-notif__list\">\n                {g.map((it) => {\n                  const inner = (\n                    <>\n                      {it.icon && <span className=\"k-notif__media\" data-tone={it.tone}>{it.icon}</span>}\n                      <span className=\"k-notif__text\">\n                        <span className=\"k-notif__item-title\">{it.title}</span>\n                        {/* خوانده‌نشده بودن فقط با نقطهٔ رنگی دیده می‌شد؛ صفحه‌خوان آن را در نام خود اعلان می‌شنود */}\n                        {!it.read && <span className=\"k-sr-only\"> {N.unreadDot}</span>}\n                        {it.body && <span className=\"k-notif__body\">{it.body}</span>}\n                        <time className=\"k-notif__time\" dateTime={it.time.toISOString()}>{formatRelative(it.time, { now: ref, locale, digits })}</time>\n                      </span>\n                    </>\n                  );\n                  const select = () => {\n                    if (!it.read) onRead?.(it.id);\n                    onSelect?.(it);\n                  };\n                  return (\n                    <li key={it.id} className=\"k-notif__item\" data-unread={it.read ? undefined : \"\"}>\n                      {it.href ? (\n                        <a className=\"k-notif__main\" href={it.href} onClick={select}>{inner}</a>\n                      ) : (\n                        <button type=\"button\" className=\"k-notif__main\" onClick={select}>{inner}</button>\n                      )}\n                      {!it.read && (\n                        <button type=\"button\" className=\"k-notif__dot\" aria-label={N.markRead} title={N.markRead} onClick={() => onRead?.(it.id)}>\n                          <span aria-hidden=\"true\" />\n                        </button>\n                      )}\n                    </li>\n                  );\n                })}\n              </ul>\n            </section>\n          ))}\n        </div>\n      )}\n      {viewAllHref && <a className=\"k-notif__all\" href={viewAllHref}>{N.viewAll}</a>}\n    </div>\n  );\n}\n\nexport interface NotificationCenterProps extends NotificationListProps {\n  open?: boolean;\n  onOpenChange?: (open: boolean) => void;\n  /** @default \"bottom-end\" */\n  placement?: \"bottom-start\" | \"bottom-end\";\n}\n\n/** دکمهٔ زنگ با شمار اعلان‌های خوانده‌نشده که فهرست اعلان‌ها را در پاپ‌اور باز می‌کند */\nexport function NotificationCenter({ open, onOpenChange, placement = \"bottom-end\", className, ...list }: NotificationCenterProps) {\n  const M = useMessages({ notifications: faNotifications });\n  const { n } = useKashiLocale();\n  const N = M.notifications;\n  const unread = list.items.filter((x) => !x.read).length;\n  // با رسیدن اعلان تازه، شمارنده یک بار تکان می‌خورد\n  const prev = useRef(unread);\n  const [bump, setBump] = useState(0);\n  useEffect(() => {\n    if (unread > prev.current) setBump((b) => b + 1);\n    prev.current = unread;\n  }, [unread]);\n  return (\n    <Popover\n      open={open}\n      onOpenChange={onOpenChange}\n      placement={placement}\n      aria-label={N.label}\n      className={cx(\"k-notif-pop\", className)}\n      trigger={\n        <button type=\"button\" className=\"k-btn k-btn--tertiary k-btn--icon k-notif__bell\" aria-label={unread ? N.button(n(unread)) : N.label}>\n          <Bell />\n          {unread > 0 && <span key={bump} className=\"k-notif__badge\" aria-hidden=\"true\">{unread > 99 ? `${n(99)}+` : n(unread)}</span>}\n        </button>\n      }\n    >\n      <NotificationList {...list} />\n    </Popover>\n  );\n}\n"
    }
  ]
}