{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "notification-settings",
  "type": "registry:block",
  "title": "Notification Settings",
  "description": "Channels you can open and tune, per-event email, push and chat toggles grouped under section switches, quiet hours on a small 24-hour track, and a digest line whose item count rolls as you change things.",
  "categories": [
    "screen",
    "Settings"
  ],
  "dependencies": [
    "lucide-react",
    "motion"
  ],
  "registryDependencies": [
    "utils",
    "https://coss.com/ui/r/segmented-control.json",
    "https://coss.com/ui/r/select.json",
    "https://coss.com/ui/r/switch.json",
    "https://coss.com/ui/r/toggle-group.json"
  ],
  "files": [
    {
      "path": "registry/devl/notification-settings.tsx",
      "type": "registry:component",
      "content": "\"use client\";\n\nimport {\n  ArrowLeftIcon,\n  BellIcon,\n  CheckIcon,\n  ChevronRightIcon,\n  CreditCardIcon,\n  KeyRoundIcon,\n  MailIcon,\n  MessagesSquareIcon,\n  MonitorIcon,\n  PaletteIcon,\n  SettingsIcon,\n  ShieldIcon,\n  SmartphoneIcon,\n  UserIcon,\n  UsersIcon,\n} from \"lucide-react\";\nimport { AnimatePresence, motion, useReducedMotion } from \"motion/react\";\nimport { type ReactNode, useEffect, useRef, useState } from \"react\";\nimport { cn } from \"@/lib/utils\";\nimport { SegmentedControl, SegmentedControlItem } from \"@/components/ui/segmented-control\";\nimport { Select, SelectItem, SelectPopup, SelectTrigger, SelectValue } from \"@/components/ui/select\";\nimport { Switch } from \"@/components/ui/switch\";\nimport { ToggleGroup, ToggleGroupItem } from \"@/components/ui/toggle-group\";\n\nexport type SettingsSectionId =\n  | \"profile\"\n  | \"appearance\"\n  | \"notifications\"\n  | \"security\"\n  | \"general\"\n  | \"members\"\n  | \"billing\"\n  | \"developer\";\n\nexport type NotifyChannelId = \"desktop\" | \"mobile\" | \"email\" | \"chat\";\nexport type NotifyChannelMode = \"all\" | \"mentions\" | \"off\";\nexport type NotifyMedium = \"email\" | \"push\" | \"chat\";\nexport type DigestFrequency = \"off\" | \"daily\" | \"weekly\";\n\nexport interface NotifyEvent {\n  id: string;\n  label: string;\n  hint: string;\n  media: NotifyMedium[];\n  pending: number;\n  mention?: boolean;\n}\n\nexport interface NotifySection {\n  id: string;\n  label: string;\n  description: string;\n  enabled: boolean;\n  events: NotifyEvent[];\n}\n\nexport interface NotifyQuietHours {\n  enabled: boolean;\n  from: number;\n  to: number;\n}\n\nexport interface NotificationSettingsProps {\n  className?: string;\n  channels?: Record<NotifyChannelId, NotifyChannelMode>;\n  sections?: NotifySection[];\n  quietHours?: NotifyQuietHours;\n  digest?: DigestFrequency;\n  onNavigate?: (section: SettingsSectionId) => void;\n}\n\nconst easeOut = [0.23, 1, 0.32, 1] as const;\n\nconst navGroups: { label: string; items: { id: SettingsSectionId; label: string; icon: ReactNode }[] }[] = [\n  {\n    label: \"Account\",\n    items: [\n      { id: \"profile\", label: \"Profile\", icon: <UserIcon /> },\n      { id: \"appearance\", label: \"Appearance\", icon: <PaletteIcon /> },\n      { id: \"notifications\", label: \"Notifications\", icon: <BellIcon /> },\n      { id: \"security\", label: \"Security\", icon: <ShieldIcon /> },\n    ],\n  },\n  {\n    label: \"Workspace\",\n    items: [\n      { id: \"general\", label: \"General\", icon: <SettingsIcon /> },\n      { id: \"members\", label: \"Members & roles\", icon: <UsersIcon /> },\n      { id: \"billing\", label: \"Billing\", icon: <CreditCardIcon /> },\n    ],\n  },\n  {\n    label: \"Developer\",\n    items: [{ id: \"developer\", label: \"API keys & webhooks\", icon: <KeyRoundIcon /> }],\n  },\n];\n\n\nconst channelMeta: { id: NotifyChannelId; label: string; icon: ReactNode; detail: string }[] = [\n  { id: \"desktop\", label: \"Desktop\", icon: <MonitorIcon />, detail: \"Banners from the Ridgeline desktop app and this browser.\" },\n  { id: \"mobile\", label: \"Mobile\", icon: <SmartphoneIcon />, detail: \"Push notifications on Pixel 9.\" },\n  { id: \"email\", label: \"Email\", icon: <MailIcon />, detail: \"Sent to ada@ridgeline.app.\" },\n  { id: \"chat\", label: \"Chat\", icon: <MessagesSquareIcon />, detail: \"Direct messages from the Ridgeline bot in your team chat.\" },\n];\n\nconst modeMeta: Record<NotifyChannelMode, { label: string; dot: string; short: string }> = {\n  all: { label: \"Enabled for all\", dot: \"bg-success\", short: \"All activity\" },\n  mentions: { label: \"Mentions only\", dot: \"bg-info\", short: \"Mentions only\" },\n  off: { label: \"Off\", dot: \"bg-muted-foreground/40\", short: \"Off\" },\n};\n\nconst media: { id: NotifyMedium; label: string; icon: ReactNode }[] = [\n  { id: \"email\", label: \"Email\", icon: <MailIcon /> },\n  { id: \"push\", label: \"Push\", icon: <SmartphoneIcon /> },\n  { id: \"chat\", label: \"Chat\", icon: <MessagesSquareIcon /> },\n];\n\nconst digestItems: { value: DigestFrequency; label: string }[] = [\n  { value: \"off\", label: \"Off\" },\n  { value: \"daily\", label: \"Daily\" },\n  { value: \"weekly\", label: \"Weekly\" },\n];\n\nconst hourItems = Array.from({ length: 24 }, (_, h) => ({\n  value: String(h),\n  label: `${String(h).padStart(2, \"0\")}:00`,\n}));\n\nconst defaultChannels: Record<NotifyChannelId, NotifyChannelMode> = {\n  desktop: \"off\",\n  mobile: \"all\",\n  email: \"all\",\n  chat: \"mentions\",\n};\n\nconst defaultSections: NotifySection[] = [\n  {\n    id: \"activity\",\n    label: \"Activity\",\n    description: \"Conversations and work that involves you.\",\n    enabled: true,\n    events: [\n      { id: \"mentions\", label: \"Mentions\", hint: \"Someone @mentions you in a doc or comment.\", media: [\"email\", \"push\", \"chat\"], pending: 3, mention: true },\n      { id: \"replies\", label: \"Replies\", hint: \"New replies on threads you started.\", media: [\"email\", \"push\"], pending: 5 },\n      { id: \"assigned\", label: \"Assigned to you\", hint: \"A task lands on your plate.\", media: [\"email\", \"push\"], pending: 2 },\n    ],\n  },\n  {\n    id: \"projects\",\n    label: \"Projects\",\n    description: \"Changes to projects you lead or follow.\",\n    enabled: true,\n    events: [\n      { id: \"status\", label: \"Status changes\", hint: \"A task you follow moves to another column.\", media: [\"chat\"], pending: 9 },\n      { id: \"due\", label: \"Due soon\", hint: \"A day before something of yours is due.\", media: [\"email\", \"push\"], pending: 1 },\n      { id: \"created\", label: \"New projects\", hint: \"A project is created in one of your teams.\", media: [], pending: 2 },\n    ],\n  },\n  {\n    id: \"billing\",\n    label: \"Billing\",\n    description: \"Invoices and plan limits for the Ridgeline workspace.\",\n    enabled: true,\n    events: [\n      { id: \"invoice\", label: \"Invoices\", hint: \"A new invoice is ready to download.\", media: [\"email\"], pending: 1 },\n      { id: \"failed\", label: \"Payment failed\", hint: \"A card is declined or about to expire.\", media: [\"email\", \"push\"], pending: 0 },\n      { id: \"usage\", label: \"Usage over 80%\", hint: \"Seats or storage close to your plan limit.\", media: [\"email\"], pending: 1 },\n    ],\n  },\n];\n\nconst defaultQuiet: NotifyQuietHours = { enabled: true, from: 22, to: 8 };\n\nfunction useCalmMotion() {\n  const prefers = useReducedMotion();\n  const [mounted, setMounted] = useState(false);\n  useEffect(() => setMounted(true), []);\n  return mounted && Boolean(prefers);\n}\n\nfunction RidgelineShell({\n  active,\n  onNavigate,\n  children,\n  className,\n}: {\n  active: SettingsSectionId;\n  onNavigate?: (section: SettingsSectionId) => void;\n  children: ReactNode;\n  className?: string;\n}) {\n  const pillsRef = useRef<HTMLDivElement>(null);\n\n  useEffect(() => {\n    const scroller = pillsRef.current;\n    const el = scroller?.querySelector<HTMLElement>(`[data-section=\"${active}\"]`);\n    if (!scroller || !el || scroller.scrollWidth <= scroller.clientWidth) return;\n    scroller.scrollLeft = el.offsetLeft - 16;\n  }, [active]);\n\n  return (\n    <div className={cn(\"flex h-[760px] w-full bg-background text-foreground\", className)}>\n      <aside className=\"hidden w-60 shrink-0 flex-col border-r bg-muted/30 px-3 py-4 md:flex\">\n        <button\n          className=\"flex h-8 cursor-pointer items-center gap-2 rounded-md px-2 text-muted-foreground text-sm outline-none transition-colors hover:bg-accent/60 hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring\"\n          type=\"button\"\n        >\n          <ArrowLeftIcon className=\"size-4\" />\n          Back to Ridgeline\n        </button>\n        <nav aria-label=\"Settings\" className=\"flex flex-col\">\n          {navGroups.map((group) => (\n            <div className=\"flex flex-col\" key={group.label}>\n              <span className=\"px-2 pt-5 pb-1.5 font-medium text-muted-foreground text-xs\">{group.label}</span>\n              <div className=\"flex flex-col gap-0.5\">\n                {group.items.map((item) => {\n                  const current = item.id === active;\n                  return (\n                    <button\n                      aria-current={current ? \"page\" : undefined}\n                      className={cn(\n                        \"flex h-8 cursor-pointer items-center gap-2 rounded-md px-2 text-left text-sm outline-none transition-colors focus-visible:ring-2 focus-visible:ring-ring [&_svg]:size-4 [&_svg]:shrink-0 [&_svg]:text-muted-foreground\",\n                        current ? \"bg-accent font-medium text-foreground\" : \"text-foreground/80 hover:bg-accent/60\",\n                      )}\n                      key={item.id}\n                      onClick={() => onNavigate?.(item.id)}\n                      type=\"button\"\n                    >\n                      {item.icon}\n                      <span className=\"truncate\">{item.label}</span>\n                    </button>\n                  );\n                })}\n              </div>\n            </div>\n          ))}\n        </nav>\n        <div className=\"mt-auto flex items-center gap-2.5 px-2 pt-4\">\n          <span className=\"flex size-7 shrink-0 items-center justify-center rounded-full bg-foreground font-medium text-[11px] text-background\">\n            AL\n          </span>\n          <span className=\"flex min-w-0 flex-col\">\n            <span className=\"truncate font-medium text-sm\">Ada Lindqvist</span>\n            <span className=\"truncate text-muted-foreground text-xs\">ada@ridgeline.app</span>\n          </span>\n        </div>\n      </aside>\n      <div className=\"flex min-w-0 flex-1 flex-col\">\n        <div className=\"md:hidden\">\n          <div className=\"flex h-12 items-center gap-2 border-b px-4\">\n            <button\n              aria-label=\"Back to Ridgeline\"\n              className=\"-ms-1.5 flex size-8 cursor-pointer items-center justify-center rounded-md text-muted-foreground outline-none hover:bg-accent/60 focus-visible:ring-2 focus-visible:ring-ring\"\n              type=\"button\"\n            >\n              <ArrowLeftIcon className=\"size-4\" />\n            </button>\n            <span className=\"font-medium text-sm\">Settings</span>\n          </div>\n          <nav\n            aria-label=\"Settings\"\n            className=\"overflow-x-auto border-b px-4 py-2.5 [scrollbar-width:none] [&::-webkit-scrollbar]:hidden\"\n            ref={pillsRef}\n          >\n            <div className=\"flex w-max gap-1.5\">\n              {navGroups.flatMap((g) => g.items).map((item) => {\n                const current = item.id === active;\n                return (\n                  <button\n                    aria-current={current ? \"page\" : undefined}\n                    className={cn(\n                      \"flex h-7 cursor-pointer items-center rounded-full px-3 text-xs outline-none transition-colors focus-visible:ring-2 focus-visible:ring-ring\",\n                      current\n                        ? \"bg-foreground font-medium text-background\"\n                        : \"bg-muted text-muted-foreground hover:text-foreground\",\n                    )}\n                    data-section={item.id}\n                    key={item.id}\n                    onClick={() => onNavigate?.(item.id)}\n                    type=\"button\"\n                  >\n                    {item.label}\n                  </button>\n                );\n              })}\n            </div>\n          </nav>\n        </div>\n        <div className=\"min-h-0 flex-1 overflow-y-auto\">{children}</div>\n      </div>\n    </div>\n  );\n}\n\n\nfunction SectionHeader({ title, description, action }: { title: string; description: ReactNode; action?: ReactNode }) {\n  return (\n    <div className=\"flex items-center gap-4\">\n      <div className=\"flex min-w-0 flex-1 flex-col gap-0.5\">\n        <h2 className=\"font-medium text-sm\">{title}</h2>\n        <p className=\"text-pretty text-muted-foreground text-sm\">{description}</p>\n      </div>\n      {action && <div className=\"shrink-0\">{action}</div>}\n    </div>\n  );\n}\n\nfunction RollingNumber({ value, reduce }: { value: number; reduce: boolean }) {\n  return (\n    <span className=\"relative inline-flex overflow-hidden align-bottom tabular-nums\">\n      <AnimatePresence initial={false} mode=\"popLayout\">\n        <motion.span\n          animate={{ y: 0, opacity: 1 }}\n          exit={{ y: reduce ? 0 : \"-70%\", opacity: 0 }}\n          initial={{ y: reduce ? 0 : \"70%\", opacity: 0 }}\n          key={value}\n          transition={{ duration: 0.2, ease: easeOut }}\n        >\n          {value}\n        </motion.span>\n      </AnimatePresence>\n    </span>\n  );\n}\n\nfunction SaveStatus({ state, reduce }: { state: \"idle\" | \"saving\" | \"saved\"; reduce: boolean }) {\n  return (\n    <span aria-live=\"polite\" className=\"inline-flex h-7 items-center text-xs\">\n      <AnimatePresence initial={false} mode=\"wait\">\n        {state !== \"idle\" && (\n          <motion.span\n            animate={{ opacity: 1, y: 0 }}\n            className={cn(\n              \"inline-flex items-center gap-1.5\",\n              state === \"saved\" ? \"text-success-foreground\" : \"text-muted-foreground\",\n            )}\n            exit={{ opacity: 0, y: reduce ? 0 : -3 }}\n            initial={{ opacity: 0, y: reduce ? 0 : 3 }}\n            key={state}\n            transition={{ duration: 0.15, ease: easeOut }}\n          >\n            {state === \"saved\" ? <CheckIcon className=\"size-3.5\" /> : <span className=\"size-1.5 animate-pulse rounded-full bg-muted-foreground\" />}\n            {state === \"saved\" ? \"Saved\" : \"Saving\"}\n          </motion.span>\n        )}\n      </AnimatePresence>\n    </span>\n  );\n}\n\nfunction ChannelRow({\n  channel,\n  mode,\n  open,\n  onOpen,\n  onMode,\n  reduce,\n}: {\n  channel: (typeof channelMeta)[number];\n  mode: NotifyChannelMode;\n  open: boolean;\n  onOpen: () => void;\n  onMode: (mode: NotifyChannelMode) => void;\n  reduce: boolean;\n}) {\n  const panelId = `channel-${channel.id}`;\n  return (\n    <div className=\"border-t first:border-t-0\">\n      <button\n        aria-controls={panelId}\n        aria-expanded={open}\n        className=\"flex w-full cursor-pointer items-center gap-3 px-4 py-3 text-left outline-none transition-colors hover:bg-accent/40 focus-visible:bg-accent/40\"\n        onClick={onOpen}\n        type=\"button\"\n      >\n        <span className=\"flex size-8 shrink-0 items-center justify-center rounded-lg border bg-background text-muted-foreground [&_svg]:size-4\">\n          {channel.icon}\n        </span>\n        <span className=\"flex min-w-0 flex-1 flex-col\">\n          <span className=\"font-medium text-sm\">{channel.label}</span>\n          <span className=\"flex items-center gap-1.5 text-muted-foreground text-xs\">\n            <span className={cn(\"size-1.5 rounded-full transition-colors duration-200\", modeMeta[mode].dot)} />\n            {modeMeta[mode].label}\n          </span>\n        </span>\n        <motion.span\n          animate={{ rotate: open ? 90 : 0 }}\n          className=\"text-muted-foreground\"\n          initial={false}\n          transition={reduce ? { duration: 0 } : { type: \"spring\", stiffness: 500, damping: 34 }}\n        >\n          <ChevronRightIcon className=\"size-4\" />\n        </motion.span>\n      </button>\n      <AnimatePresence initial={false}>\n        {open && (\n          <motion.div\n            animate={{ height: \"auto\", opacity: 1 }}\n            className=\"overflow-hidden\"\n            exit={{ height: 0, opacity: 0 }}\n            id={panelId}\n            initial={{ height: 0, opacity: 0 }}\n            transition={reduce ? { duration: 0 } : { duration: 0.22, ease: easeOut }}\n          >\n            <div className=\"flex flex-wrap items-center gap-x-4 gap-y-2.5 px-4 pb-3.5 sm:ps-15\">\n              <p className=\"min-w-0 flex-1 basis-44 text-pretty text-muted-foreground text-xs\">{channel.detail}</p>\n              <SegmentedControl aria-label={`${channel.label} notifications`} size=\"sm\">\n                {(Object.keys(modeMeta) as NotifyChannelMode[]).map((m) => (\n                  <SegmentedControlItem\n                    aria-pressed={mode === m}\n                    data-pressed={mode === m ? \"\" : undefined}\n                    key={m}\n                    onClick={() => onMode(m)}\n                  >\n                    {modeMeta[m].short}\n                  </SegmentedControlItem>\n                ))}\n              </SegmentedControl>\n            </div>\n          </motion.div>\n        )}\n      </AnimatePresence>\n    </div>\n  );\n}\n\nfunction QuietTrack({ from, to }: { from: number; to: number }) {\n  const segments = from < to ? [[from, to]] : [[from, 24], [0, to]];\n  return (\n    <div aria-hidden className=\"flex w-full max-w-64 flex-col gap-1\">\n      <div className=\"relative h-1.5 overflow-hidden rounded-full bg-muted\">\n        {segments.map(([a, b], i) => (\n          <span\n            className=\"absolute inset-y-0 rounded-full bg-indigo-500 transition-[left,width] duration-200 ease-out dark:bg-indigo-400\"\n            key={i}\n            style={{ left: `${(a / 24) * 100}%`, width: `${((b - a) / 24) * 100}%` }}\n          />\n        ))}\n      </div>\n      <div className=\"flex justify-between font-mono text-[10px] text-muted-foreground\">\n        <span>00</span>\n        <span>06</span>\n        <span>12</span>\n        <span>18</span>\n        <span>24</span>\n      </div>\n    </div>\n  );\n}\n\nfunction HourSelect({ label, value, onChange }: { label: string; value: number; onChange: (h: number) => void }) {\n  return (\n    <Select items={hourItems} onValueChange={(v) => v != null && onChange(Number(v))} value={String(value)}>\n      <SelectTrigger aria-label={label} className=\"w-24 min-w-0 font-mono tabular-nums\" size=\"sm\">\n        <SelectValue />\n      </SelectTrigger>\n      <SelectPopup>\n        {hourItems.map((h) => (\n          <SelectItem className=\"font-mono tabular-nums\" key={h.value} value={h.value}>\n            {h.label}\n          </SelectItem>\n        ))}\n      </SelectPopup>\n    </Select>\n  );\n}\n\nexport function NotificationSettings({\n  className,\n  channels: initialChannels = defaultChannels,\n  sections: initialSections = defaultSections,\n  quietHours = defaultQuiet,\n  digest: initialDigest = \"weekly\",\n  onNavigate,\n}: NotificationSettingsProps) {\n  const reduce = useCalmMotion();\n  const [channels, setChannels] = useState(initialChannels);\n  const [openChannel, setOpenChannel] = useState<NotifyChannelId | null>(null);\n  const [sections, setSections] = useState(initialSections);\n  const [quiet, setQuiet] = useState(quietHours);\n  const [digest, setDigest] = useState<DigestFrequency>(initialDigest);\n  const [save, setSave] = useState<{ state: \"idle\" | \"saving\" | \"saved\"; tick: number }>({ state: \"idle\", tick: 0 });\n\n  useEffect(() => {\n    if (save.state === \"idle\") return;\n    const t = setTimeout(\n      () => setSave((s) => ({ ...s, state: s.state === \"saving\" ? \"saved\" : \"idle\" })),\n      save.state === \"saving\" ? 500 : 1600,\n    );\n    return () => clearTimeout(t);\n  }, [save.state, save.tick]);\n\n  const touched = () => setSave((s) => ({ state: \"saving\", tick: s.tick + 1 }));\n\n  const mediumOff: Record<NotifyMedium, boolean> = {\n    email: channels.email === \"off\",\n    push: channels.desktop === \"off\" && channels.mobile === \"off\",\n    chat: channels.chat === \"off\",\n  };\n\n  const digestCount = sections.reduce(\n    (n, s) =>\n      s.enabled\n        ? n +\n          s.events.reduce(\n            (m, e) =>\n              e.media.includes(\"email\") && !mediumOff.email && (channels.email === \"all\" || e.mention) ? m + e.pending : m,\n            0,\n          )\n        : n,\n    0,\n  );\n\n  const digestLine =\n    digest === \"off\"\n      ? \"Off. Each email is sent as it happens.\"\n      : mediumOff.email\n        ? \"Paused while email notifications are off.\"\n        : null;\n\n  const isDefault =\n    JSON.stringify({ channels, sections, quiet, digest }) ===\n    JSON.stringify({ channels: initialChannels, sections: initialSections, quiet: quietHours, digest: initialDigest });\n\n  const restore = () => {\n    setChannels(initialChannels);\n    setSections(initialSections);\n    setQuiet(quietHours);\n    setDigest(initialDigest);\n    setOpenChannel(null);\n    touched();\n  };\n\n  const restoreLink = (\n    <button\n      className=\"cursor-pointer rounded-sm text-muted-foreground text-sm underline-offset-4 outline-none transition-colors hover:text-foreground hover:underline focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-default disabled:opacity-50 disabled:hover:text-muted-foreground disabled:hover:no-underline\"\n      disabled={isDefault}\n      onClick={restore}\n      type=\"button\"\n    >\n      Restore defaults\n    </button>\n  );\n\n  return (\n    <RidgelineShell active=\"notifications\" className={className} onNavigate={onNavigate}>\n      <div className=\"mx-auto w-full max-w-2xl px-6 py-10 md:px-10\">\n        <div className=\"flex items-start gap-4\">\n          <div className=\"min-w-0 flex-1\">\n            <h1 className=\"font-semibold text-2xl tracking-tight\">Notifications</h1>\n            <p className=\"mt-1 text-muted-foreground text-sm\">Choose what reaches you, and where.</p>\n          </div>\n          <div className=\"flex shrink-0 items-center gap-3 pt-1.5\">\n            <SaveStatus reduce={reduce} state={save.state} />\n            <span className=\"hidden sm:inline-flex\">{restoreLink}</span>\n          </div>\n        </div>\n\n        <section className=\"mt-10\">\n          <SectionHeader description=\"How each channel reaches you. Everything always lands in your Ridgeline inbox.\" title=\"Where we notify you\" />\n          <div className=\"mt-3 overflow-hidden rounded-xl border bg-card\">\n            {channelMeta.map((c) => (\n              <ChannelRow\n                channel={c}\n                key={c.id}\n                mode={channels[c.id]}\n                onMode={(m) => {\n                  setChannels((all) => ({ ...all, [c.id]: m }));\n                  touched();\n                }}\n                onOpen={() => setOpenChannel((o) => (o === c.id ? null : c.id))}\n                open={openChannel === c.id}\n                reduce={reduce}\n              />\n            ))}\n          </div>\n        </section>\n\n        {sections.map((section) => (\n          <section className=\"mt-10\" key={section.id}>\n            <SectionHeader\n              action={\n                <Switch\n                  aria-label={`${section.label} notifications`}\n                  checked={section.enabled}\n                  onCheckedChange={(v) => {\n                    setSections((all) => all.map((s) => (s.id === section.id ? { ...s, enabled: v } : s)));\n                    touched();\n                  }}\n                />\n              }\n              description={section.description}\n              title={section.label}\n            />\n            <div className=\"mt-3 overflow-hidden rounded-xl border bg-card\">\n              <div className=\"flex items-center gap-4 border-b px-4 py-2.5 font-medium text-muted-foreground text-xs\">\n                <span className=\"flex-1\">Event</span>\n                <span aria-hidden className=\"flex\">\n                  {media.map((m) => (\n                    <span className=\"w-9 text-center\" key={m.id}>\n                      {m.label}\n                    </span>\n                  ))}\n                </span>\n              </div>\n              <ul className={cn(\"divide-y transition-opacity duration-200\", !section.enabled && \"opacity-50\")}>\n                {section.events.map((e) => (\n                  <li className=\"flex items-center gap-4 px-4 py-3.5\" key={e.id}>\n                    <div className=\"flex min-w-0 flex-1 flex-col gap-0.5\">\n                      <span className=\"font-medium text-sm\">{e.label}</span>\n                      <span className=\"text-pretty text-muted-foreground text-xs\">{e.hint}</span>\n                    </div>\n                    <ToggleGroup\n                      aria-label={`Channels for ${e.label}`}\n                      className=\"shrink-0\"\n                      disabled={!section.enabled}\n                      multiple\n                      onValueChange={(value) => {\n                        setSections((all) =>\n                          all.map((s) =>\n                            s.id === section.id\n                              ? { ...s, events: s.events.map((x) => (x.id === e.id ? { ...x, media: value as NotifyMedium[] } : x)) }\n                              : s,\n                          ),\n                        );\n                        touched();\n                      }}\n                      size=\"sm\"\n                      value={e.media}\n                      variant=\"outline\"\n                    >\n                      {media.map((m) => (\n                        <ToggleGroupItem\n                          aria-label={`${m.label} for ${e.label}${mediumOff[m.id] ? \" (channel off)\" : \"\"}`}\n                          className=\"w-9 text-muted-foreground/50 data-pressed:text-foreground\"\n                          disabled={!section.enabled || mediumOff[m.id]}\n                          key={m.id}\n                          value={m.id}\n                        >\n                          {m.icon}\n                        </ToggleGroupItem>\n                      ))}\n                    </ToggleGroup>\n                  </li>\n                ))}\n              </ul>\n            </div>\n          </section>\n        ))}\n\n        <section className=\"mt-10\">\n          <SectionHeader description=\"When notifications can wait.\" title=\"Delivery\" />\n          <div className=\"mt-3 overflow-hidden rounded-xl border bg-card\">\n            <div>\n              <label className=\"flex cursor-pointer items-center gap-4 px-4 py-3.5\">\n                <span className=\"flex min-w-0 flex-1 flex-col gap-0.5\">\n                  <span className=\"font-medium text-sm\">Quiet hours</span>\n                  <span className=\"text-pretty text-muted-foreground text-xs\">\n                    {quiet.enabled\n                      ? `Push and chat stay silent ${hourItems[quiet.from].label}–${hourItems[quiet.to].label}, every day.`\n                      : \"Mute push and chat overnight. Email waits for you anyway.\"}\n                  </span>\n                </span>\n                <Switch\n                  checked={quiet.enabled}\n                  onCheckedChange={(v) => {\n                    setQuiet((q) => ({ ...q, enabled: v }));\n                    touched();\n                  }}\n                />\n              </label>\n              <AnimatePresence initial={false}>\n                {quiet.enabled && (\n                  <motion.div\n                    animate={{ height: \"auto\", opacity: 1 }}\n                    className=\"overflow-hidden\"\n                    exit={{ height: 0, opacity: 0 }}\n                    initial={{ height: 0, opacity: 0 }}\n                    transition={reduce ? { duration: 0 } : { duration: 0.22, ease: easeOut }}\n                  >\n                    <div className=\"flex flex-wrap items-center gap-x-6 gap-y-3 px-4 pb-4\">\n                      <div className=\"flex items-center gap-2 text-muted-foreground text-xs\">\n                        <HourSelect\n                          label=\"Quiet hours start\"\n                          onChange={(h) => {\n                            if (h === quiet.to) return;\n                            setQuiet((q) => ({ ...q, from: h }));\n                            touched();\n                          }}\n                          value={quiet.from}\n                        />\n                        <span>to</span>\n                        <HourSelect\n                          label=\"Quiet hours end\"\n                          onChange={(h) => {\n                            if (h === quiet.from) return;\n                            setQuiet((q) => ({ ...q, to: h }));\n                            touched();\n                          }}\n                          value={quiet.to}\n                        />\n                      </div>\n                      <div className=\"min-w-40 flex-1\">\n                        <QuietTrack from={quiet.from} to={quiet.to} />\n                      </div>\n                    </div>\n                  </motion.div>\n                )}\n              </AnimatePresence>\n            </div>\n            <div className=\"flex items-center gap-4 border-t px-4 py-3.5\">\n              <div className=\"flex min-w-0 flex-1 flex-col gap-0.5\">\n                <span className=\"font-medium text-sm\">Email digest</span>\n                <span aria-live=\"polite\" className=\"text-pretty text-muted-foreground text-xs\">\n                  {digestLine ?? (\n                    <>\n                      Next digest {digest === \"daily\" ? \"tomorrow\" : \"Monday\"} 09:00 ·{\" \"}\n                      <span className=\"font-medium text-foreground\">\n                        <RollingNumber reduce={reduce} value={digestCount} /> {digestCount === 1 ? \"item\" : \"items\"}\n                      </span>\n                    </>\n                  )}\n                </span>\n              </div>\n              <Select\n                items={digestItems}\n                onValueChange={(v) => {\n                  if (!v) return;\n                  setDigest(v as DigestFrequency);\n                  touched();\n                }}\n                value={digest}\n              >\n                <SelectTrigger aria-label=\"Email digest\" className=\"w-28 min-w-0\" size=\"sm\">\n                  <SelectValue />\n                </SelectTrigger>\n                <SelectPopup>\n                  {digestItems.map((d) => (\n                    <SelectItem key={d.value} value={d.value}>\n                      {d.label}\n                    </SelectItem>\n                  ))}\n                </SelectPopup>\n              </Select>\n            </div>\n          </div>\n        </section>\n        <div className=\"mt-8 flex justify-center sm:hidden\">{restoreLink}</div>\n      </div>\n    </RidgelineShell>\n  );\n}\n"
    }
  ]
}