{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "offline-changes",
  "title": "Offline Changes",
  "type": "registry:block",
  "files": [
    {
      "path": "packages/registry-native/blocks/offline-changes/OfflineChanges.tsx",
      "content": "import * as React from 'react'\nimport { View, type ViewProps } from 'react-native'\nimport { Alert, AlertDescription, AlertTitle } from '@/components/ui/alert'\nimport { Badge } from '@/components/ui/badge'\nimport { Button } from '@/components/ui/button'\nimport { Text } from '@/components/ui/text'\nimport { useAnnouncement } from '@/lib/accessibility'\nimport { cn } from '@/lib/utils'\n\nexport type OfflineChange = {\n  id: string\n  title: string\n  detail?: string\n} & ({ status: 'waiting' | 'sending' | 'synced' } | { status: 'failed'; reason: string })\n\nexport interface OfflineChangesProps extends ViewProps {\n  className?: string\n  title?: string\n  changes?: readonly OfflineChange[]\n  offline?: boolean\n  /** Return your request promise or update the supplied row to syncing when a retry starts. */\n  onRetry?: (id: string) => void | Promise<void>\n  labels?: Partial<OfflineChangesLabels>\n}\n\ninterface OfflineChangesLabels {\n  offlineTitle: string\n  offlineDescription: string\n  emptyTitle: string\n  emptyDescription: string\n  waiting: string\n  sending: string\n  failed: string\n  synced: string\n  retry: string\n  retryAction: (title: string) => string\n}\n\nconst sample: OfflineChange[] = [\n  { id: 'checklist', title: 'Workshop checklist', detail: 'Two updates', status: 'waiting' },\n  { id: 'notes', title: 'Equipment notes', status: 'failed', reason: 'The server did not respond.' },\n]\n\nconst defaultLabels: OfflineChangesLabels = {\n  offlineTitle: 'You’re offline',\n  offlineDescription: 'Reconnect to sync the changes waiting to send.',\n  emptyTitle: 'No changes to sync',\n  emptyDescription: 'Offline updates will appear here when they’re ready to send.',\n  waiting: 'Waiting',\n  sending: 'Syncing',\n  failed: 'Needs attention',\n  synced: 'Synced',\n  retry: 'Retry',\n  retryAction: (title) => `Retry ${title}`,\n}\n\nexport function OfflineChanges({\n  className,\n  title = 'Offline changes',\n  changes = sample,\n  offline = false,\n  onRetry,\n  labels,\n  ...props\n}: OfflineChangesProps) {\n  const copy = React.useMemo(() => ({ ...defaultLabels, ...labels }), [labels])\n  const previous = React.useRef(new Map(changes.map(({ id, status }) => [id, status])))\n  const requests = React.useRef(new Set<string>())\n  const [pending, setPending] = React.useState<ReadonlySet<string>>(new Set())\n  const [statement, setStatement] = React.useState('')\n  useAnnouncement(statement)\n\n  React.useEffect(() => {\n    const updates = changes.filter(({ id, status }) => previous.current.has(id) && previous.current.get(id) !== status)\n    previous.current = new Map(changes.map(({ id, status }) => [id, status]))\n    if (updates.length) setStatement(updates.map(({ title, status }) => `${title}. ${copy[status]}`).join('. '))\n  }, [changes, copy])\n\n  async function retry(id: string) {\n    if (offline || !onRetry || requests.current.has(id)) return\n    requests.current.add(id)\n    setPending(new Set(requests.current))\n    try {\n      await onRetry(id)\n    } catch {\n      // The caller owns the failure details and can keep or replace the failed row.\n    } finally {\n      requests.current.delete(id)\n      setPending(new Set(requests.current))\n    }\n  }\n\n  return (\n    <View {...props} className={cn('gap-4', className)}>\n      <Text size=\"title\" accessibilityRole=\"header\">\n        {title}\n      </Text>\n      {offline ? (\n        <Alert>\n          <AlertTitle>{copy.offlineTitle}</AlertTitle>\n          <AlertDescription>{copy.offlineDescription}</AlertDescription>\n        </Alert>\n      ) : null}\n      {changes.length === 0 ? (\n        <View className=\"gap-1 rounded-lg border border-border bg-card p-4\">\n          <Text className=\"font-semibold\">{copy.emptyTitle}</Text>\n          <Text size=\"sm\" variant=\"muted\">\n            {copy.emptyDescription}\n          </Text>\n        </View>\n      ) : (\n        <View className=\"overflow-hidden rounded-xl border border-border bg-card\">\n          {changes.map((change, index) => (\n            <View key={change.id} className={cn('gap-2 p-4', index > 0 && 'border-t border-border')}>\n              <View className=\"flex-row flex-wrap items-start justify-between gap-2\">\n                <View className=\"min-w-[144px] flex-1 gap-1\">\n                  <Text className=\"font-semibold\">{change.title}</Text>\n                  {change.detail ? (\n                    <Text size=\"sm\" variant=\"muted\">\n                      {change.detail}\n                    </Text>\n                  ) : null}\n                </View>\n                <Badge variant={change.status === 'failed' ? 'outline' : 'secondary'} text={copy[change.status]} />\n              </View>\n              {change.status === 'failed' ? (\n                <>\n                  <Text size=\"sm\" variant=\"muted\">\n                    {change.reason}\n                  </Text>\n                  {onRetry ? (\n                    <Button\n                      variant=\"outline\"\n                      className=\"self-start\"\n                      disabled={offline}\n                      loading={pending.has(change.id)}\n                      accessibilityLabel={copy.retryAction(change.title)}\n                      onPress={() => {\n                        void retry(change.id)\n                      }}\n                    >\n                      {copy.retry}\n                    </Button>\n                  ) : null}\n                </>\n              ) : null}\n            </View>\n          ))}\n        </View>\n      )}\n    </View>\n  )\n}\n",
      "type": "registry:block",
      "target": "~/components/blocks/offline-changes/OfflineChanges.tsx"
    },
    {
      "path": "packages/registry-native/blocks/offline-changes/index.ts",
      "content": "export { OfflineChanges, type OfflineChange, type OfflineChangesProps } from './OfflineChanges'\n",
      "type": "registry:block",
      "target": "~/components/blocks/offline-changes/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/badge.json",
    "https://native.uipkge.dev/r/native/button.json",
    "https://native.uipkge.dev/r/native/text.json",
    "https://native.uipkge.dev/r/native/utils.json"
  ],
  "description": "Caller-owned offline changes with waiting, syncing, failed, synced, and recovery states.",
  "categories": [
    "workflow"
  ]
}