{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "delivery-instructions",
  "title": "Delivery Instructions",
  "type": "registry:block",
  "files": [
    {
      "path": "packages/registry-native/blocks/delivery-instructions/DeliveryInstructions.tsx",
      "content": "import { useRef, useState } from 'react'\nimport { View, type ViewProps } from 'react-native'\nimport { Button } from '@/components/ui/button'\nimport { FormField } from '@/components/ui/form-field'\nimport { RadioGroup, RadioGroupItem } from '@/components/ui/radio-group'\nimport { Sheet, SheetClose, SheetContent, SheetTrigger } from '@/components/ui/sheet'\nimport { Text } from '@/components/ui/text'\nimport { Textarea } from '@/components/ui/textarea'\nimport { useAnnouncement } from '@/lib/accessibility'\nimport { cn } from '@/lib/utils'\n\nexport interface DeliveryHandoffOption {\n  id: string\n  label: string\n  unavailableReason?: string\n}\n\nexport interface DeliveryInstructionsValue {\n  handoff: string | null\n  note?: string\n}\n\nexport interface DeliveryInstructionsProps extends Omit<ViewProps, 'children'> {\n  className?: string\n  title?: string\n  value: DeliveryInstructionsValue\n  /** Caller-owned options with unique and nonempty IDs. */\n  options?: readonly DeliveryHandoffOption[]\n  /** Return false or reject to retain the draft. Update value when saving succeeds. */\n  onSave: (draft: DeliveryInstructionsValue) => void | boolean | Promise<void | boolean>\n  labels?: Partial<\n    Record<\n      | 'edit'\n      | 'close'\n      | 'handoff'\n      | 'unavailable'\n      | 'empty'\n      | 'choose'\n      | 'note'\n      | 'cancel'\n      | 'save'\n      | 'failed'\n      | 'saved',\n      string\n    >\n  >\n}\n\nconst standardHandoff: readonly DeliveryHandoffOption[] = [\n  { id: 'leave-at-door', label: 'Leave at the door' },\n  { id: 'hand-it-to-me', label: 'Hand it to me' },\n]\n\nexport function DeliveryInstructions({\n  className,\n  title = 'Delivery instructions',\n  value,\n  options = standardHandoff,\n  onSave,\n  labels,\n  ...props\n}: DeliveryInstructionsProps) {\n  const submitting = useRef(false)\n  const [draft, setDraft] = useState<DeliveryInstructionsValue | null>(null)\n  const [saving, setSaving] = useState(false)\n  const [failed, setFailed] = useState(false)\n  const [saved, setSaved] = useState(false)\n  const persisted = options.find((option) => option.id === value.handoff && !option.unavailableReason)\n  const handoff = options.find((option) => option.id === draft?.handoff && !option.unavailableReason)\n  const hasChoices = options.some((option) => !option.unavailableReason)\n  const edit = labels?.edit ?? 'Edit delivery instructions'\n  const saveLabel = labels?.save ?? 'Save instructions'\n  const cancel = labels?.cancel ?? 'Cancel'\n  const failedMessage = labels?.failed ?? 'Couldn’t save your instructions. Try again.'\n  useAnnouncement(failed ? failedMessage : saved ? (labels?.saved ?? 'Delivery instructions saved') : undefined)\n\n  async function save() {\n    if (!draft || !handoff || submitting.current) return\n    submitting.current = true\n    setSaving(true)\n    setFailed(false)\n    try {\n      if ((await onSave({ handoff: handoff.id, note: draft.note?.trim() ?? '' })) === false) {\n        setFailed(true)\n        return\n      }\n      setDraft(null)\n      setSaved(true)\n    } catch {\n      setFailed(true)\n    } finally {\n      submitting.current = false\n      setSaving(false)\n    }\n  }\n\n  return (\n    <View {...props} className={cn('gap-[12px]', className)}>\n      <View className=\"gap-[4px]\">\n        <Text size=\"title\" accessibilityRole=\"header\">\n          {title}\n        </Text>\n        <Text className=\"font-medium\">{persisted?.label ?? labels?.choose ?? 'Choose a handoff method.'}</Text>\n        {value.note?.trim() ? <Text variant=\"muted\">{value.note}</Text> : null}\n      </View>\n      <Sheet\n        open={draft !== null}\n        onOpenChange={(open) => {\n          if (submitting.current) return\n          setFailed(false)\n          setSaved(false)\n          setDraft(open ? { ...value } : null)\n        }}\n      >\n        <SheetTrigger variant=\"outline\" accessibilityLabel={edit}>\n          {edit}\n        </SheetTrigger>\n        <SheetContent\n          title={edit}\n          closeLabel={labels?.close ?? 'Close delivery instructions'}\n          dismissOnBackdropPress={!saving}\n        >\n          {draft ? (\n            <>\n              <View className=\"gap-[4px]\">\n                <Text size=\"sm\" className=\"font-semibold\">\n                  {labels?.handoff ?? 'Handoff method'}\n                </Text>\n                {options.length > 0 ? (\n                  <RadioGroup\n                    value={handoff?.id ?? ''}\n                    accessibilityLabel={labels?.handoff ?? 'Handoff method'}\n                    disabled={saving}\n                    onValueChange={(next) => {\n                      if (!submitting.current) setDraft((current) => current && { ...current, handoff: next })\n                    }}\n                    className=\"gap-0\"\n                  >\n                    {options.map(({ id, label, unavailableReason }) => (\n                      <RadioGroupItem\n                        key={id}\n                        value={id}\n                        label={label}\n                        disabled={Boolean(unavailableReason)}\n                        accessibilityLabel={unavailableReason ? `${label}, ${unavailableReason}` : label}\n                        className={unavailableReason && !saving ? 'opacity-100' : undefined}\n                      >\n                        {unavailableReason ? (\n                          <Text size=\"sm\" variant=\"muted\">\n                            {unavailableReason}\n                          </Text>\n                        ) : null}\n                      </RadioGroupItem>\n                    ))}\n                  </RadioGroup>\n                ) : null}\n                {!hasChoices ? (\n                  <Text size=\"sm\" variant=\"muted\">\n                    {labels?.empty ?? 'No handoff methods are available.'}\n                  </Text>\n                ) : draft.handoff !== null && !handoff ? (\n                  <Text size=\"sm\" variant=\"muted\">\n                    {labels?.unavailable ?? 'Your previous method is unavailable. Choose another.'}\n                  </Text>\n                ) : null}\n              </View>\n              <FormField label={labels?.note ?? 'Delivery note (optional)'}>\n                {(control) => (\n                  <Textarea\n                    {...control}\n                    editable={!saving}\n                    value={draft.note ?? ''}\n                    onChangeText={(note) => {\n                      if (!submitting.current) setDraft((current) => current && { ...current, note })\n                    }}\n                  />\n                )}\n              </FormField>\n              {failed ? (\n                <Text accessibilityRole=\"alert\" className=\"text-destructive\">\n                  {failedMessage}\n                </Text>\n              ) : null}\n              <View className=\"gap-[8px]\">\n                <Button\n                  accessibilityLabel={saveLabel}\n                  disabled={!handoff}\n                  loading={saving}\n                  onPress={() => {\n                    void save()\n                  }}\n                >\n                  {saveLabel}\n                </Button>\n                <SheetClose variant=\"outline\" accessibilityLabel={cancel} disabled={saving}>\n                  {cancel}\n                </SheetClose>\n              </View>\n            </>\n          ) : null}\n        </SheetContent>\n      </Sheet>\n    </View>\n  )\n}\n",
      "type": "registry:block",
      "target": "~/components/blocks/delivery-instructions/DeliveryInstructions.tsx"
    },
    {
      "path": "packages/registry-native/blocks/delivery-instructions/index.ts",
      "content": "export {\n  DeliveryInstructions,\n  type DeliveryHandoffOption,\n  type DeliveryInstructionsProps,\n  type DeliveryInstructionsValue,\n} from './DeliveryInstructions'\n",
      "type": "registry:block",
      "target": "~/components/blocks/delivery-instructions/index.ts"
    }
  ],
  "dependencies": [],
  "devDependencies": [],
  "registryDependencies": [
    "https://native.uipkge.dev/r/native/accessibility.json",
    "https://native.uipkge.dev/r/native/button.json",
    "https://native.uipkge.dev/r/native/form-field.json",
    "https://native.uipkge.dev/r/native/radio-group.json",
    "https://native.uipkge.dev/r/native/sheet.json",
    "https://native.uipkge.dev/r/native/text.json",
    "https://native.uipkge.dev/r/native/textarea.json",
    "https://native.uipkge.dev/r/native/utils.json"
  ],
  "description": "Edit delivery handoff and optional notes with a caller-owned save and recoverable drafts.",
  "categories": [
    "commerce",
    "logistics"
  ]
}