{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "draft-recovery",
  "title": "Draft Recovery",
  "type": "registry:block",
  "files": [
    {
      "path": "packages/registry-native/blocks/draft-recovery/DraftRecovery.tsx",
      "content": "import * as React from 'react'\nimport { View, type ViewProps } from 'react-native'\nimport { Alert, AlertDescription } from '@/components/ui/alert'\nimport {\n  AlertDialog,\n  AlertDialogAction,\n  AlertDialogCancel,\n  AlertDialogContent,\n  AlertDialogTrigger,\n} from '@/components/ui/alert-dialog'\nimport { Button } from '@/components/ui/button'\nimport { Text } from '@/components/ui/text'\nimport { useAnnouncement } from '@/lib/accessibility'\nimport { cn } from '@/lib/utils'\n\nexport interface DraftRecoveryEntry {\n  id: string\n  title: string\n  preview?: string\n  /** A caller-localized short date or time. */\n  savedAt?: string\n}\n\ntype DraftAction = 'inspect' | 'resume' | 'discard'\ntype DraftActionHandler = (id: string) => void | boolean | Promise<void | boolean>\n\nconst defaultLabels = {\n  savedAt: (time: string) => `Saved ${time}`,\n  inspect: 'Inspect draft',\n  inspecting: 'Opening preview…',\n  retryInspect: 'Retry preview',\n  resume: 'Resume draft',\n  resuming: 'Opening draft…',\n  retryResume: 'Retry opening draft',\n  discard: 'Discard draft',\n  discarding: 'Discarding draft…',\n  retryDiscard: 'Retry discarding',\n  keep: 'Keep draft',\n  confirm: 'Discard saved draft',\n  confirmTitle: 'Discard this draft?',\n  confirmDescription: (title: string) => `“${title}” will be removed from saved drafts.`,\n  close: 'Close confirmation',\n  failed: (action: DraftAction) =>\n    action === 'discard'\n      ? 'Could not discard this draft. It is still saved.'\n      : 'Could not open this draft. It is still saved.',\n}\n\nexport interface DraftRecoveryProps extends Omit<ViewProps, 'children'> {\n  className?: string\n  draft?: DraftRecoveryEntry | null\n  onInspect?: DraftActionHandler\n  onResume?: DraftActionHandler\n  onDiscard?: DraftActionHandler\n  disabled?: boolean\n  labels?: Partial<typeof defaultLabels>\n}\n\nexport function DraftRecovery({ draft, ...props }: DraftRecoveryProps) {\n  return draft ? <DraftCard key={draft.id} draft={draft} {...props} /> : null\n}\n\nfunction DraftCard({\n  className,\n  draft,\n  onInspect,\n  onResume,\n  onDiscard,\n  disabled = false,\n  labels,\n  ...props\n}: Omit<DraftRecoveryProps, 'draft'> & { draft: DraftRecoveryEntry }) {\n  const copy = { ...defaultLabels, ...labels }\n  const [pending, setPending] = React.useState<DraftAction>()\n  const [failed, setFailed] = React.useState<DraftAction>()\n  const busy = React.useRef(false)\n  const blocked = disabled || !!pending\n  const error = failed ? copy.failed(failed) : undefined\n  useAnnouncement(error)\n\n  async function run(action: DraftAction, handler: DraftActionHandler) {\n    if (disabled || busy.current) return\n    busy.current = true\n    setPending(action)\n    setFailed(undefined)\n    try {\n      if ((await handler(draft.id)) === false) setFailed(action)\n    } catch {\n      setFailed(action)\n    } finally {\n      busy.current = false\n      setPending(undefined)\n    }\n  }\n\n  const resumeLabel = pending === 'resume' ? copy.resuming : failed === 'resume' ? copy.retryResume : copy.resume\n  const inspectLabel = pending === 'inspect' ? copy.inspecting : failed === 'inspect' ? copy.retryInspect : copy.inspect\n  const discardLabel = pending === 'discard' ? copy.discarding : failed === 'discard' ? copy.retryDiscard : copy.discard\n\n  return (\n    <View {...props} className={cn('gap-4 rounded-xl border border-border bg-card p-4', className)}>\n      <View className=\"gap-1\">\n        <Text accessibilityRole=\"header\" size=\"xl\">\n          {draft.title}\n        </Text>\n        {draft.savedAt ? (\n          <Text size=\"sm\" variant=\"muted\">\n            {copy.savedAt(draft.savedAt)}\n          </Text>\n        ) : null}\n        {draft.preview ? <Text>{draft.preview}</Text> : null}\n      </View>\n      {error ? (\n        <Alert accessibilityRole=\"none\" variant=\"destructive\">\n          <AlertDescription>{error}</AlertDescription>\n        </Alert>\n      ) : null}\n      {onResume ? (\n        <Button\n          accessibilityLabel={resumeLabel}\n          loading={pending === 'resume'}\n          disabled={blocked && pending !== 'resume'}\n          onPress={() => {\n            void run('resume', onResume)\n          }}\n        >\n          {resumeLabel}\n        </Button>\n      ) : null}\n      {onInspect || onDiscard ? (\n        <View className=\"flex-row flex-wrap gap-2\">\n          {onInspect ? (\n            <Button\n              variant=\"outline\"\n              accessibilityLabel={inspectLabel}\n              loading={pending === 'inspect'}\n              disabled={blocked && pending !== 'inspect'}\n              onPress={() => {\n                void run('inspect', onInspect)\n              }}\n            >\n              {inspectLabel}\n            </Button>\n          ) : null}\n          {onDiscard ? (\n            <AlertDialog>\n              <AlertDialogTrigger\n                variant=\"ghost\"\n                accessibilityLabel={discardLabel}\n                loading={pending === 'discard'}\n                disabled={blocked && pending !== 'discard'}\n                onPress={(event) => {\n                  if (busy.current) event.preventDefault()\n                }}\n              >\n                {discardLabel}\n              </AlertDialogTrigger>\n              <AlertDialogContent\n                title={copy.confirmTitle}\n                description={copy.confirmDescription(draft.title)}\n                closeLabel={copy.close}\n              >\n                <View className=\"flex-row flex-wrap gap-2\">\n                  <AlertDialogCancel variant=\"outline\" accessibilityLabel={copy.keep}>\n                    {copy.keep}\n                  </AlertDialogCancel>\n                  <AlertDialogAction\n                    variant=\"destructive\"\n                    accessibilityLabel={copy.confirm}\n                    disabled={blocked}\n                    onPress={() => {\n                      void run('discard', onDiscard)\n                    }}\n                  >\n                    {copy.confirm}\n                  </AlertDialogAction>\n                </View>\n              </AlertDialogContent>\n            </AlertDialog>\n          ) : null}\n        </View>\n      ) : null}\n    </View>\n  )\n}\n",
      "type": "registry:block",
      "target": "~/components/blocks/draft-recovery/DraftRecovery.tsx"
    },
    {
      "path": "packages/registry-native/blocks/draft-recovery/index.ts",
      "content": "export { DraftRecovery, type DraftRecoveryEntry, type DraftRecoveryProps } from './DraftRecovery'\n",
      "type": "registry:block",
      "target": "~/components/blocks/draft-recovery/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/alert-dialog.json",
    "https://native.uipkge.dev/r/native/button.json",
    "https://native.uipkge.dev/r/native/text.json"
  ],
  "description": "A saved draft summary with inspect, resume, and confirmed discard actions plus recoverable failures.",
  "categories": [
    "workflow",
    "editing"
  ]
}