{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "shipping-address",
  "title": "Shipping Address",
  "type": "registry:block",
  "files": [
    {
      "path": "packages/registry-native/blocks/shipping-address/ShippingAddress.tsx",
      "content": "import * as React from 'react'\nimport { TextInput, View, useWindowDimensions, type ViewProps } from 'react-native'\nimport { Button } from '@/components/ui/button'\nimport { FormField } from '@/components/ui/form-field'\nimport { Input, type InputProps } from '@/components/ui/input'\nimport { Text } from '@/components/ui/text'\nimport { useAnnouncement } from '@/lib/accessibility'\nimport { renderTextChildren } from '@/lib/label-children'\nimport { cn } from '@/lib/utils'\n\nexport interface ShippingAddressValue {\n  name: string\n  line1: string\n  line2: string\n  city: string\n  region: string\n  postalCode: string\n}\n\ntype Field = keyof ShippingAddressValue\ntype FieldErrors = Partial<Record<Field, string>>\n\nexport interface ShippingAddressProps extends Omit<ViewProps, 'children'> {\n  className?: string\n  title?: string\n  value?: ShippingAddressValue\n  defaultValue?: ShippingAddressValue\n  onFieldChange?: (field: Field, draft: string) => void\n  onSubmit?: (address: ShippingAddressValue) => void | boolean | Promise<void | boolean>\n  validate?: (address: ShippingAddressValue) => FieldErrors\n  regionRequired?: boolean\n  postalCodeRequired?: boolean\n  countryField?: React.ReactNode | ((props: { disabled: boolean }) => React.ReactNode)\n  labels?: Partial<Record<Field, string>>\n  requiredMessage?: (label: string) => string\n  validationSummary?: string\n  failedMessage?: string\n  submitLabel?: string\n}\n\nconst empty: ShippingAddressValue = { name: '', line1: '', line2: '', city: '', region: '', postalCode: '' }\nconst fieldLabels: Record<Field, string> = {\n  name: 'Recipient name',\n  line1: 'Street address',\n  line2: 'Apartment or unit',\n  city: 'City or town',\n  region: 'State, province, or region',\n  postalCode: 'Postal code',\n}\nconst fields: Field[] = ['name', 'line1', 'line2', 'city', 'region', 'postalCode']\n\nexport function ShippingAddress({\n  className,\n  title = 'Delivery address',\n  value,\n  defaultValue = empty,\n  onFieldChange,\n  onSubmit,\n  validate,\n  regionRequired = false,\n  postalCodeRequired = false,\n  countryField,\n  labels,\n  requiredMessage = (label) => `Enter ${label.toLocaleLowerCase()}.`,\n  validationSummary = 'Check the highlighted address fields.',\n  failedMessage = 'We couldn’t save this address. Try again.',\n  submitLabel = 'Use this address',\n  ...props\n}: ShippingAddressProps) {\n  const { width, fontScale } = useWindowDimensions()\n  const [internal, setInternal] = React.useState(defaultValue)\n  const draft = React.useRef(defaultValue)\n  const [errors, setErrors] = React.useState<FieldErrors>({})\n  const [firstError, setFirstError] = React.useState<{ field: Field }>()\n  const [failed, setFailed] = React.useState(false)\n  const [busy, setBusy] = React.useState(false)\n  const submitting = React.useRef(false)\n  const inputs = React.useRef<Partial<Record<Field, React.ComponentRef<typeof TextInput> | null>>>({})\n  const shown = value ?? internal\n  const copy = { ...fieldLabels, ...labels }\n  const required: Field[] = ['name', 'line1', 'city']\n  if (regionRequired) required.push('region')\n  if (postalCodeRequired) required.push('postalCode')\n  const validationIssue = fields.some((field) => Boolean(errors[field]))\n  useAnnouncement(failed ? failedMessage : validationIssue ? validationSummary : undefined)\n\n  React.useEffect(() => {\n    if (firstError) inputs.current[firstError.field]?.focus()\n  }, [firstError])\n\n  async function submit(finalPostalCode?: string) {\n    if (submitting.current || !onSubmit) return\n    if (value === undefined && finalPostalCode !== undefined && finalPostalCode !== draft.current.postalCode) {\n      draft.current = { ...draft.current, postalCode: finalPostalCode }\n      setInternal(draft.current)\n      onFieldChange?.('postalCode', finalPostalCode)\n    }\n    const current = value ?? draft.current\n    const address = {\n      name: current.name.trim(),\n      line1: current.line1.trim(),\n      line2: current.line2.trim(),\n      city: current.city.trim(),\n      region: current.region.trim(),\n      postalCode: current.postalCode.trim(),\n    }\n    const nextErrors = { ...validate?.(address) }\n    for (const field of required) {\n      if (!address[field]) nextErrors[field] = requiredMessage(copy[field])\n    }\n    const first = fields.find((field) => Boolean(nextErrors[field]))\n    setErrors(nextErrors)\n    setFirstError(first ? { field: first } : undefined)\n    setFailed(false)\n    if (first) return\n    submitting.current = true\n    setBusy(true)\n    try {\n      if ((await onSubmit(address)) === false) setFailed(true)\n    } catch {\n      setFailed(true)\n    } finally {\n      submitting.current = false\n      setBusy(false)\n    }\n  }\n\n  function field(key: Field, autoComplete: InputProps['autoComplete'], next?: Field) {\n    return (\n      <FormField label={copy[key]} required={required.includes(key)} error={errors[key]} announceError={false}>\n        {(control) => (\n          <Input\n            {...control}\n            ref={(input) => {\n              inputs.current[key] = input\n            }}\n            value={shown[key]}\n            editable={!busy}\n            autoComplete={autoComplete}\n            autoCapitalize={key === 'postalCode' ? 'characters' : 'words'}\n            autoCorrect={false}\n            returnKeyType={next ? 'next' : 'done'}\n            submitBehavior={next ? 'submit' : 'blurAndSubmit'}\n            onSubmitEditing={(event) => {\n              if (next) inputs.current[next]?.focus()\n              else void submit(event.nativeEvent.text)\n            }}\n            onChangeText={(text) => {\n              if (submitting.current) return\n              if (value === undefined) {\n                draft.current = { ...draft.current, [key]: text }\n                setInternal(draft.current)\n              }\n              onFieldChange?.(key, text)\n              if (errors[key]) setErrors((current) => ({ ...current, [key]: undefined }))\n              if (firstError?.field === key) setFirstError(undefined)\n              if (failed) setFailed(false)\n            }}\n          />\n        )}\n      </FormField>\n    )\n  }\n\n  const compact = width < 390 || fontScale >= 1.4\n  return (\n    <View {...props} className={cn('gap-4', className)}>\n      <Text size=\"title\" accessibilityRole=\"header\">\n        {title}\n      </Text>\n      {renderTextChildren(typeof countryField === 'function' ? countryField({ disabled: busy }) : countryField)}\n      {field('name', 'name', 'line1')}\n      {field('line1', 'address-line1', 'line2')}\n      {field('line2', 'address-line2', 'city')}\n      {field('city', 'postal-address-locality', 'region')}\n      <View className={cn('gap-4', !compact && 'flex-row items-start')}>\n        <View className={cn(!compact && 'min-w-0 flex-1')}>\n          {field('region', 'postal-address-region', 'postalCode')}\n        </View>\n        <View className={cn(!compact && 'min-w-0 flex-1')}>{field('postalCode', 'postal-code')}</View>\n      </View>\n      {failed || validationIssue ? (\n        <Text size=\"sm\" className=\"text-destructive\">\n          {failed ? failedMessage : validationSummary}\n        </Text>\n      ) : null}\n      {onSubmit ? (\n        <Button\n          accessibilityLabel={submitLabel}\n          loading={busy}\n          onPress={() => {\n            void submit()\n          }}\n        >\n          {submitLabel}\n        </Button>\n      ) : null}\n    </View>\n  )\n}\n",
      "type": "registry:block",
      "target": "~/components/blocks/shipping-address/ShippingAddress.tsx"
    },
    {
      "path": "packages/registry-native/blocks/shipping-address/index.ts",
      "content": "export { ShippingAddress, type ShippingAddressProps, type ShippingAddressValue } from './ShippingAddress'\n",
      "type": "registry:block",
      "target": "~/components/blocks/shipping-address/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/input.json",
    "https://native.uipkge.dev/r/native/label-children.json",
    "https://native.uipkge.dev/r/native/text.json",
    "https://native.uipkge.dev/r/native/utils.json"
  ],
  "description": "Native address fields with system autofill, configurable regional requirements, and recoverable submission.",
  "categories": [
    "commerce"
  ]
}