{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "gulf-iban-input",
  "type": "registry:ui",
  "title": "Gulf IBAN input",
  "description": "Groups a Gulf IBAN in fours as it is typed and checks its length and checksum for each country.",
  "dependencies": [
    "@dualkit/format"
  ],
  "registryDependencies": [
    "input",
    "https://dualkit.dev/r/gulf-field.json"
  ],
  "files": [
    {
      "path": "gulf/gulf-iban-input.tsx",
      "type": "registry:ui",
      "target": "components/gulf/gulf-iban-input.tsx",
      "content": "import { parseIban, toWesternDigits, type GulfIbanCountry, type Iban, type IbanError, 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 GulfIbanResult = Result<Iban, IbanError>\n\nexport type GulfIbanInputProps = GulfFieldText<IbanError> & {\n  /** The electronic form: capitals and Western digits, no spaces. */\n  value: string\n  onChange: (value: string) => void\n  /** format's parseIban result for the new value. */\n  onResult?: (result: GulfIbanResult) => void\n  /** Accept only IBANs from this country. */\n  country?: GulfIbanCountry\n  numerals?: Numerals\n}\n\n/** The longest IBAN anywhere has 34 characters. */\nconst MAX_LENGTH = 34\n\n/** Fours, as IBANs are printed. format's formatIban only groups a complete, valid IBAN, so the partial one is grouped here. */\nconst groupInFours = (value: string): string => value.replace(/(.{4})(?=.)/g, '$1 ')\n\n/** An IBAN, grouped in fours as it is typed, left to right in both languages. */\nexport function GulfIbanInput(props: GulfIbanInputProps) {\n  const { value, onChange, onResult, country, numerals = 'latn', label, help, error, errorMessages, id, name, placeholder, disabled, required, className } = props\n  const read = (v: string): GulfIbanResult => parseIban(v, country ? { country } : {})\n  const shown = useShownError(read(value), error, errorMessages)\n  const mask: Mask = {\n    normalize: (raw) => toWesternDigits(raw).toUpperCase().replace(/[^A-Z0-9]/g, '').slice(0, MAX_LENGTH),\n    display: (v) => withNumerals(groupInFours(v), numerals),\n    separator: / /,\n  }\n  const input = useMaskedInput(value, mask, (next) => {\n    onChange(next)\n    onResult?.(read(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\" autoCapitalize=\"characters\" autoComplete=\"off\" spellCheck={false}\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."
}
