{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "age-gate-date-field",
  "title": "Age Gate Date Field",
  "description": "A date of birth that decides whether someone is old enough, with the exact date they become eligible, without ever blocking typing. Use this when a product or purchase has a minimum age and the person should learn when they will qualify.",
  "registryDependencies": [
    "@tealmac/date-field",
    "@tealmac/date-time-core"
  ],
  "files": [
    {
      "path": "registry/patterns/age-gate-date-field/age-gate-date-field.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\n\nimport { DateField } from \"@/components/ui/date-field\"\nimport {\n  addYears,\n  formatDate,\n  resolveLocale,\n  today as todayISO,\n} from \"@/components/ui/date-time-core\"\n\nexport interface AgeGateDateFieldProps {\n  minAge?: number\n  onValueChange?: (date: string | null, eligible: boolean) => void\n  today?: string\n  locale?: string\n}\n\n/** The day a person born on `birth` turns `minAge` (29 February becomes 1 March in other years). */\nexport function eligibleOn(birth: string, minAge: number) {\n  const d = addYears(birth, minAge)\n  return birth.slice(5) === \"02-29\" && d.slice(5) === \"02-28\"\n    ? `${d.slice(0, 4)}-03-01`\n    : d\n}\n\nexport function AgeGateDateField({\n  minAge = 18,\n  onValueChange,\n  today,\n  locale,\n}: AgeGateDateFieldProps) {\n  const loc = resolveLocale(locale)\n  const now = today ?? todayISO()\n  const [date, setDate] = React.useState<string | null>(null)\n  const from = date ? eligibleOn(date, minAge) : null\n  const eligible = !!from && from <= now\n\n  return (\n    <div className=\"flex flex-col gap-1.5\">\n      <DateField\n        label=\"Date of birth\"\n        locale={loc}\n        value={date}\n        invalid={!!date && !eligible}\n        onValueChange={(next) => {\n          setDate(next)\n          onValueChange?.(next, !!next && eligibleOn(next, minAge) <= now)\n        }}\n      />\n      <p\n        role=\"status\"\n        className={\n          date && !eligible\n            ? \"text-destructive text-sm\"\n            : \"text-muted-foreground text-sm\"\n        }\n      >\n        {!from\n          ? `You must be ${minAge} or older.`\n          : eligible\n            ? \"Thanks, you can continue.\"\n            : `You can sign up from ${formatDate(from, loc, { dateStyle: \"medium\" })}.`}\n      </p>\n    </div>\n  )\n}\n",
      "type": "registry:block"
    }
  ],
  "type": "registry:block"
}