{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "vacation-rental-minimum-stay",
  "title": "Vacation Rental Minimum Stay",
  "description": "Typed check-in and check-out dates where the minimum number of nights depends on the check-in date, such as a weekend, a holiday week or the high season. Use this when a rental host sets a longer minimum stay for some dates than for others.",
  "registryDependencies": [
    "@tealmac/date-range-field",
    "@tealmac/date-time-core"
  ],
  "files": [
    {
      "path": "registry/patterns/vacation-rental-minimum-stay/vacation-rental-minimum-stay.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\n\nimport { DateRangeField } from \"@/components/ui/date-range-field\"\nimport {\n  nightsBetween,\n  weekday,\n  type DateRange,\n} from \"@/components/ui/date-time-core\"\n\nexport interface StayRule {\n  from: string\n  to: string\n  nights: number\n  reason: string\n}\n\nexport interface VacationRentalMinimumStayProps {\n  value?: DateRange | null\n  defaultValue?: DateRange | null\n  onValueChange?: (stay: DateRange | null) => void\n  rules?: StayRule[]\n  weekendNights?: number\n  defaultNights?: number\n  locale?: string\n}\n\nexport function minimumStay(\n  checkIn: string,\n  rules: StayRule[],\n  { weekendNights = 2, defaultNights = 1 } = {}\n): { nights: number; reason: string } {\n  // The longest matching rule wins.\n  const hit = rules\n    .filter((r) => checkIn >= r.from && checkIn <= r.to)\n    .sort((a, b) => b.nights - a.nights)[0]\n  if (hit) return { nights: hit.nights, reason: hit.reason }\n  if ([5, 6].includes(weekday(checkIn)) && weekendNights > defaultNights)\n    return { nights: weekendNights, reason: \"weekend check-in\" }\n  return { nights: defaultNights, reason: \"standard stay\" }\n}\n\nexport function VacationRentalMinimumStay({\n  value,\n  defaultValue = null,\n  onValueChange,\n  rules = [],\n  weekendNights = 2,\n  defaultNights = 1,\n  locale,\n}: VacationRentalMinimumStayProps) {\n  const [inner, setInner] = React.useState<DateRange | null>(defaultValue)\n  const stay = value === undefined ? inner : value\n  const [checkIn, setCheckIn] = React.useState<string | null>(\n    defaultValue?.from ?? null\n  )\n  const rule = checkIn\n    ? minimumStay(checkIn, rules, { weekendNights, defaultNights })\n    : null\n\n  return (\n    <div className=\"flex flex-col gap-2\">\n      <DateRangeField\n        label=\"Stay\"\n        startLabel=\"Check-in\"\n        endLabel=\"Check-out\"\n        locale={locale}\n        value={stay}\n        minDays={rule ? rule.nights + 1 : undefined}\n        onValueChange={(next) => {\n          if (value === undefined) setInner(next)\n          if (next) setCheckIn(next.from)\n          onValueChange?.(next)\n        }}\n      />\n      {rule ? (\n        <p role=\"status\" className=\"text-muted-foreground text-sm\">\n          Minimum stay for this check-in: {rule.nights} night\n          {rule.nights === 1 ? \"\" : \"s\"} ({rule.reason}).\n          {stay ? ` You chose ${nightsBetween(stay.from, stay.to)}.` : \"\"}\n        </p>\n      ) : (\n        <p role=\"status\" className=\"text-muted-foreground text-sm\">\n          Enter a check-in date to see the minimum stay.\n        </p>\n      )}\n    </div>\n  )\n}\n",
      "type": "registry:block"
    }
  ],
  "type": "registry:block"
}