{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "notification-preferences",
  "title": "Notification Preferences",
  "type": "registry:block",
  "files": [
    {
      "path": "packages/registry-native/blocks/notification-preferences/NotificationPreferences.tsx",
      "content": "import * as React from 'react'\nimport { View, type ViewProps } from 'react-native'\nimport { Alert, AlertDescription } from '@/components/ui/alert'\nimport { Button } from '@/components/ui/button'\nimport {\n  List,\n  ListItem,\n  ListItemContent,\n  ListItemDescription,\n  ListItemTitle,\n  ListSeparator,\n} from '@/components/ui/list'\nimport { Switch } from '@/components/ui/switch'\nimport { Text } from '@/components/ui/text'\nimport { useAnnouncement } from '@/lib/accessibility'\nimport { cn } from '@/lib/utils'\n\ntype Preferences = Readonly<Record<string, boolean>>\n\nconst defaultLabels = {\n  applied: 'All changes applied',\n  pending: (count: number) => `${count} unsaved ${count === 1 ? 'change' : 'changes'}`,\n  apply: 'Apply changes',\n  applying: 'Applying changes…',\n  discard: 'Discard changes',\n  retry: 'Try again',\n  empty: 'No notification preferences available.',\n}\n\nexport interface NotificationPreferencesProps extends ViewProps {\n  className?: string\n  /** NotificationPreference children with unique names. */\n  children?: React.ReactNode\n  applied: Preferences\n  draft: Preferences\n  onDraftChange: (name: string, checked: boolean) => void\n  onApply: (values: Record<string, boolean>) => void\n  onDiscard?: () => void\n  applying?: boolean\n  disabled?: boolean\n  /** Keeps the draft available for retry or discard. */\n  error?: string\n  labels?: Partial<typeof defaultLabels>\n}\n\nexport interface NotificationPreferenceProps extends ViewProps {\n  className?: string\n  name: string\n  label: string\n  description?: string\n  disabled?: boolean\n}\n\nconst PreferencesContext = React.createContext<{\n  values: Preferences\n  blocked: boolean\n  change: (name: string, value: boolean) => void\n} | null>(null)\n\nfunction preferenceRows(children: React.ReactNode): React.ReactElement<NotificationPreferenceProps>[] {\n  return React.Children.toArray(children).flatMap((child) => {\n    if (!React.isValidElement<{ children?: React.ReactNode }>(child)) return []\n    if (child.type === React.Fragment) return preferenceRows(child.props.children)\n    return child.type === NotificationPreference ? [child as React.ReactElement<NotificationPreferenceProps>] : []\n  })\n}\n\nexport function NotificationPreferences({\n  className,\n  children,\n  applied,\n  draft,\n  onDraftChange,\n  onApply,\n  onDiscard,\n  applying = false,\n  disabled = false,\n  error,\n  labels,\n  ...props\n}: NotificationPreferencesProps) {\n  const rows = preferenceRows(children)\n  const copy = { ...defaultLabels, ...labels }\n  const blocked = applying || disabled\n  const values = { ...applied }\n  let changes = 0\n  for (const row of rows) {\n    const { name, disabled: unavailable } = row.props\n    const before = applied[name] === true\n    const next = unavailable ? before : (draft[name] ?? before)\n    values[name] = next\n    if (next !== before) changes++\n  }\n  const [requested, setRequested] = React.useState(false)\n  const message = applying ? copy.applying : changes ? copy.pending(changes) : copy.applied\n  const actionLabel = applying ? copy.applying : error ? copy.retry : copy.apply\n  useAnnouncement(applying ? message : error || (requested && !changes ? copy.applied : undefined))\n\n  return (\n    <PreferencesContext.Provider\n      value={{\n        values,\n        blocked,\n        change(name, checked) {\n          if (!blocked) onDraftChange(name, checked)\n        },\n      }}\n    >\n      <View {...props} className={cn('gap-3', className)}>\n        {rows.length ? (\n          <>\n            <List>\n              {rows.map((row, index) => (\n                <React.Fragment key={row.props.name}>\n                  {index ? <ListSeparator /> : null}\n                  {row}\n                </React.Fragment>\n              ))}\n            </List>\n            <Text size=\"sm\" variant=\"muted\">\n              {message}\n            </Text>\n            {error && !applying ? (\n              <Alert variant=\"destructive\">\n                <AlertDescription>{error}</AlertDescription>\n              </Alert>\n            ) : null}\n            <Button\n              accessibilityLabel={actionLabel}\n              disabled={disabled || !changes}\n              loading={applying}\n              onPress={() => {\n                if (blocked || !changes) return\n                setRequested(true)\n                onApply({ ...values })\n              }}\n            >\n              {actionLabel}\n            </Button>\n            {changes && onDiscard ? (\n              <Button\n                variant=\"ghost\"\n                accessibilityLabel={copy.discard}\n                disabled={blocked}\n                onPress={() => {\n                  if (blocked) return\n                  setRequested(false)\n                  onDiscard()\n                }}\n              >\n                {copy.discard}\n              </Button>\n            ) : null}\n          </>\n        ) : (\n          <View className=\"items-center rounded-xl border border-border px-4 py-8\">\n            <Text className=\"text-center font-medium\">{copy.empty}</Text>\n          </View>\n        )}\n      </View>\n    </PreferencesContext.Provider>\n  )\n}\n\nexport function NotificationPreference({\n  className,\n  name,\n  label,\n  description,\n  disabled,\n  accessibilityLabel,\n  accessibilityState,\n  ...props\n}: NotificationPreferenceProps) {\n  const group = React.useContext(PreferencesContext)\n  if (!group) throw new Error('NotificationPreference must be inside NotificationPreferences')\n  const checked = group.values[name] === true\n  const blocked = group.blocked || !!disabled\n\n  return (\n    <ListItem\n      {...props}\n      accessible\n      accessibilityRole=\"switch\"\n      accessibilityLabel={accessibilityLabel ?? [label, description].filter(Boolean).join(', ')}\n      accessibilityState={{ ...accessibilityState, checked, disabled: blocked }}\n      disabled={blocked}\n      onPress={blocked ? undefined : () => group.change(name, !checked)}\n      className={cn('gap-3', className)}\n    >\n      <ListItemContent>\n        <ListItemTitle>{label}</ListItemTitle>\n        {description ? <ListItemDescription>{description}</ListItemDescription> : null}\n      </ListItemContent>\n      <View\n        aria-hidden\n        pointerEvents=\"none\"\n        accessibilityElementsHidden\n        importantForAccessibility=\"no-hide-descendants\"\n      >\n        <Switch checked={checked} accessible={false} focusable={false} tabIndex={-1} />\n      </View>\n    </ListItem>\n  )\n}\n",
      "type": "registry:block",
      "target": "~/components/blocks/notification-preferences/NotificationPreferences.tsx"
    },
    {
      "path": "packages/registry-native/blocks/notification-preferences/index.ts",
      "content": "export {\n  NotificationPreference,\n  NotificationPreferences,\n  type NotificationPreferenceProps,\n  type NotificationPreferencesProps,\n} from './NotificationPreferences'\n",
      "type": "registry:block",
      "target": "~/components/blocks/notification-preferences/index.ts"
    }
  ],
  "dependencies": [],
  "devDependencies": [],
  "registryDependencies": [
    "https://native.uipkge.dev/r/native/accessibility.json",
    "https://native.uipkge.dev/r/native/alert.json",
    "https://native.uipkge.dev/r/native/button.json",
    "https://native.uipkge.dev/r/native/list.json",
    "https://native.uipkge.dev/r/native/switch.json",
    "https://native.uipkge.dev/r/native/text.json"
  ],
  "description": "A caller-owned settings section with draft topic switches, explicit apply and discard, and recoverable save errors.",
  "categories": [
    "settings"
  ]
}