{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "dob-input",
  "title": "Date of Birth Input",
  "description": "DD / MM / YYYY date of birth fields that auto-advance and only emit real dates.",
  "dependencies": [
    "react-number-format@^5.4.5"
  ],
  "registryDependencies": [
    "input-group"
  ],
  "files": [
    {
      "path": "components/dentil/dob-input/dob-input.tsx",
      "content": "'use client';\n\nimport * as React from 'react';\nimport { NumericFormat } from 'react-number-format';\n\nimport { InputGroup, InputGroupInput, InputGroupText } from '@/components/ui/input-group';\nimport { cn } from '@/lib/utils';\n\nexport interface DOB {\n  day: number;\n  month: number;\n  year: number;\n}\n\nexport interface DOBInputProps extends Omit<\n  React.ComponentProps<'input'>,\n  'value' | 'onChange' | 'type' | 'defaultValue' | 'ref' | 'size'\n> {\n  value: DOB | null | undefined;\n  /** Called with the date once day, month and a four-digit year form a real date, and with `undefined` otherwise. */\n  onChange: (value: DOB | undefined) => void;\n}\n\n/** The text in each field, so a leading zero survives while typing. */\ntype Parts = { day: string; month: string; year: string };\n\nconst pad = (n: number) => String(n).padStart(2, '0');\n\nconst toParts = (value: DOB | null | undefined): Parts =>\n  value ? { day: pad(value.day), month: pad(value.month), year: String(value.year) } : { day: '', month: '', year: '' };\n\nfunction toDob(parts: Parts): DOB | undefined {\n  const day = Number.parseInt(parts.day, 10);\n  const month = Number.parseInt(parts.month, 10);\n  const year = Number.parseInt(parts.year, 10);\n  if (!day || !month || !(year >= 1000)) return undefined;\n  const date = new Date(year, month - 1, day);\n  if (date.getMonth() !== month - 1 || date.getDate() !== day) return undefined;\n  return { day, month, year };\n}\n\nconst dobKey = (value: DOB | null | undefined) => (value ? `${value.year}-${value.month}-${value.day}` : '');\n\nconst segmentClassName = 'flex-none px-0 text-center tabular-nums';\n\nexport function DOBInput({ value, onChange, disabled = false, className, ...props }: DOBInputProps) {\n  const [parts, setParts] = React.useState<Parts>(() => toParts(value));\n  const [prevKey, setPrevKey] = React.useState(() => dobKey(value));\n  const monthRef = React.useRef<HTMLInputElement>(null);\n  const yearRef = React.useRef<HTMLInputElement>(null);\n\n  const valueKey = dobKey(value);\n  if (valueKey !== prevKey) {\n    setPrevKey(valueKey);\n    if (valueKey !== dobKey(toDob(parts))) setParts(toParts(value));\n  }\n\n  const update = (patch: Partial<Parts>) => {\n    const next = { ...parts, ...patch };\n    setParts(next);\n    onChange(toDob(next));\n  };\n\n  const ariaInvalid = props['aria-invalid'];\n\n  return (\n    <InputGroup data-slot=\"dob-input\" data-disabled={disabled} className={cn('w-fit px-1', className)}>\n      <NumericFormat\n        customInput={InputGroupInput}\n        className={cn(segmentClassName, 'w-9')}\n        placeholder=\"DD\"\n        aria-label=\"Day\"\n        inputMode=\"numeric\"\n        autoComplete=\"bday-day\"\n        decimalScale={0}\n        allowLeadingZeros\n        allowNegative={false}\n        disabled={disabled}\n        value={parts.day}\n        isAllowed={({ floatValue }) => floatValue === undefined || floatValue <= 31}\n        onValueChange={({ floatValue, formattedValue }, { source }) => {\n          if (source !== 'event') return;\n          update({ day: formattedValue });\n          if (formattedValue.length === 2 || (formattedValue.length === 1 && (floatValue ?? 0) > 3)) {\n            monthRef.current?.focus();\n          }\n        }}\n        onFocus={(e) => e.target.select()}\n        {...props}\n      />\n      <InputGroupText aria-hidden=\"true\">/</InputGroupText>\n      <NumericFormat\n        customInput={InputGroupInput}\n        getInputRef={monthRef}\n        className={cn(segmentClassName, 'w-10')}\n        placeholder=\"MM\"\n        aria-label=\"Month\"\n        aria-invalid={ariaInvalid}\n        inputMode=\"numeric\"\n        autoComplete=\"bday-month\"\n        decimalScale={0}\n        allowLeadingZeros\n        allowNegative={false}\n        disabled={disabled}\n        value={parts.month}\n        isAllowed={({ floatValue }) => floatValue === undefined || floatValue <= 12}\n        onValueChange={({ floatValue, formattedValue }, { source }) => {\n          if (source !== 'event') return;\n          update({ month: formattedValue });\n          if (formattedValue.length === 2 || (formattedValue.length === 1 && (floatValue ?? 0) > 1)) {\n            yearRef.current?.focus();\n          }\n        }}\n        onFocus={(e) => e.target.select()}\n      />\n      <InputGroupText aria-hidden=\"true\">/</InputGroupText>\n      <NumericFormat\n        customInput={InputGroupInput}\n        getInputRef={yearRef}\n        className={cn(segmentClassName, 'w-14 md:w-12')}\n        placeholder=\"YYYY\"\n        aria-label=\"Year\"\n        aria-invalid={ariaInvalid}\n        inputMode=\"numeric\"\n        autoComplete=\"bday-year\"\n        decimalScale={0}\n        allowLeadingZeros={false}\n        allowNegative={false}\n        disabled={disabled}\n        value={parts.year}\n        isAllowed={({ floatValue }) => floatValue === undefined || floatValue <= 9999}\n        onValueChange={({ formattedValue }, { source }) => {\n          if (source === 'event') update({ year: formattedValue });\n        }}\n        onFocus={(e) => e.target.select()}\n      />\n    </InputGroup>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/dentil/dob-input/dob-input.tsx"
    }
  ],
  "type": "registry:component"
}
