{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "gulf-national-id-input",
  "type": "registry:ui",
  "title": "Gulf national ID input",
  "description": "An Emirates ID number, hyphenated as it is typed and checked against the 784 prefix and check digit.",
  "dependencies": [
    "@dualkit/format"
  ],
  "registryDependencies": [
    "input",
    "https://dualkit.dev/r/gulf-field.json"
  ],
  "files": [
    {
      "path": "gulf/gulf-national-id-input.tsx",
      "type": "registry:ui",
      "target": "components/gulf/gulf-national-id-input.tsx",
      "content": "import { parseEmiratesId, toWesternDigits, type EmiratesId, type EmiratesIdError, type Numerals, type Result } from '@dualkit/format'\nimport { Input } from '@/components/ui/input'\nimport { GulfField, cx, LTR_PLACEHOLDER, useMaskedInput, useShownError, withNumerals, type GulfFieldText, type Mask } from './gulf-field'\n\nexport type GulfNationalIdResult = Result<EmiratesId, EmiratesIdError>\n\nexport type GulfNationalIdInputProps = GulfFieldText<EmiratesIdError> & {\n  /** The 15 digits, Western, without hyphens. */\n  value: string\n  onChange: (value: string) => void\n  /** format's parseEmiratesId result for the new value. */\n  onResult?: (result: GulfNationalIdResult) => void\n  numerals?: Numerals\n}\n\n/** 784-YYYY-NNNNNNN-C. Saudi ID and Iqama wait until format has a tested validator. */\nconst GROUPS = [3, 4, 7, 1] as const\nconst LENGTH = 15\n\n/** Hyphens between the groups typed so far. formatEmiratesId only formats a complete, valid ID, so the partial one is grouped here. */\nfunction hyphenate(digits: string): string {\n  const parts: string[] = []\n  let start = 0\n  for (const size of GROUPS) {\n    if (start >= digits.length) break\n    parts.push(digits.slice(start, start + size))\n    start += size\n  }\n  return parts.join('-')\n}\n\nconst ID_MASK: Mask = {\n  normalize: (raw) => toWesternDigits(raw).replace(/\\D/g, '').slice(0, LENGTH),\n  display: hyphenate,\n  separator: /-/,\n}\n\n/** An Emirates ID number, hyphenated as it is typed, left to right in both languages. */\nexport function GulfNationalIdInput(props: GulfNationalIdInputProps) {\n  const { value, onChange, onResult, numerals = 'latn', label, help, error, errorMessages, id, name, placeholder, disabled, required, className } = props\n  const shown = useShownError(parseEmiratesId(value), error, errorMessages)\n  const input = useMaskedInput(value, { ...ID_MASK, display: (v) => withNumerals(hyphenate(v), numerals) }, (next) => {\n    onChange(next)\n    onResult?.(parseEmiratesId(next))\n  })\n\n  return (\n    <GulfField id={id} label={label} help={help} error={shown.error} className={className}>\n      {(aria) => (\n        <Input {...aria} {...input} dir=\"ltr\" inputMode=\"numeric\" autoComplete=\"off\"\n          name={name} placeholder={placeholder} disabled={disabled} required={required}\n          className={cx('text-start font-mono', LTR_PLACEHOLDER)} onBlur={shown.onBlur} />\n      )}\n    </GulfField>\n  )\n}\n"
    }
  ],
  "docs": "Needs a shadcn project (Tailwind and the shadcn CSS variables). Works with and without `shadcn init --rtl`: set dir=\"rtl\" on <html> or a parent for Arabic. Pass every label, help text and error message as props."
}
