{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "cancellation-deadline-note",
  "title": "Cancellation Deadline Note",
  "description": "A check-in date field that works out the last moment for free cancellation and tells the guest whether it is still open, closing soon or already past. Use this when a booking is free to cancel until a cut-off before the stay and the guest should see that date as they choose dates.",
  "registryDependencies": [
    "@tealmac/date-field",
    "@tealmac/date-time-core"
  ],
  "files": [
    {
      "path": "registry/patterns/cancellation-deadline-note/cancellation-deadline-note.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\n\nimport { DateField } from \"@/components/ui/date-field\"\nimport {\n  addMinutesToDateTime,\n  diffMinutes,\n  formatDateTime,\n  nowLocal,\n  toDateTime,\n} from \"@/components/ui/date-time-core\"\n\nexport interface CancellationDeadlineNoteProps {\n  value?: string | null\n  defaultValue?: string | null\n  onValueChange?: (checkIn: string | null) => void\n  hoursBefore?: number\n  checkInTime?: string\n  now?: string\n  locale?: string\n}\n\nexport function cancellationDeadline(\n  checkIn: string,\n  time: string,\n  hoursBefore: number\n) {\n  return addMinutesToDateTime(toDateTime(checkIn, time), -hoursBefore * 60)\n}\n\nexport function CancellationDeadlineNote({\n  value,\n  defaultValue = null,\n  onValueChange,\n  hoursBefore = 48,\n  checkInTime = \"15:00\",\n  now: nowProp,\n  locale,\n}: CancellationDeadlineNoteProps) {\n  const now = nowProp ?? nowLocal()\n  const [inner, setInner] = React.useState<string | null>(defaultValue)\n  const checkIn = value === undefined ? inner : value\n\n  let note = \"Choose a check-in date to see the cancellation deadline.\"\n  let state: \"open\" | \"soon\" | \"closed\" | null = null\n  if (checkIn) {\n    const deadline = cancellationDeadline(checkIn, checkInTime, hoursBefore)\n    const left = diffMinutes(now, deadline)\n    if (left <= 0) {\n      state = \"closed\"\n      note = \"Non-refundable: the free cancellation period has ended.\"\n    } else {\n      state = left < 24 * 60 ? \"soon\" : \"open\"\n      note = `Free cancellation until ${formatDateTime(deadline, locale)}${state === \"soon\" ? \" (less than 24 hours left)\" : \"\"}.`\n    }\n  }\n\n  return (\n    <div className=\"flex flex-col gap-2\">\n      <DateField\n        label=\"Check-in date\"\n        locale={locale}\n        value={checkIn}\n        onValueChange={(next) => {\n          if (value === undefined) setInner(next)\n          onValueChange?.(next)\n        }}\n      />\n      <p\n        role=\"status\"\n        data-state={state ?? undefined}\n        className=\"data-[state=closed]:text-destructive text-sm data-[state=soon]:font-medium\"\n      >\n        {note}\n      </p>\n    </div>\n  )\n}\n",
      "type": "registry:block"
    }
  ],
  "type": "registry:block"
}