// Copyright (c) Meta Platforms, Inc. and affiliates. 'use client'; import {useState} from 'react'; import { useCalendarConstraints, useCalendarDays, type CalendarDay, } from '@astryxdesign/core/Calendar'; import {Button} from '@astryxdesign/core/Button'; import {HStack, VStack} from '@astryxdesign/core/Layout'; import {Text} from '@astryxdesign/core/Text'; // Hotel closed on Mondays (day === 1) const isNotMonday = (date: Date) => date.getDay() !== 1; export default function UseCalendarConstraintsHookUsage() { const [checkIn, setCheckIn] = useState(null); const [checkOut, setCheckOut] = useState(null); // June 2026 season: open Jun 5 – Jun 25, max 7 nights (8-day span), closed Mondays. // When checkOut is already chosen, clear rangeAnchor so full season remains viewable without lingering span restrictions. const {isDateDisabled} = useCalendarConstraints({ min: '2026-06-05', max: '2026-06-25', maxRangeSpan: 8, rangeAnchor: checkOut ? null : checkIn, dateConstraints: [isNotMonday], }); const {weeks, dayNames} = useCalendarDays({ year: 2026, month: 6, weekStartsOn: 0, hasVariableRowCount: true, }); const handleSelect = (day: CalendarDay) => { if (day.isOutside || isDateDisabled(day.date)) { return; } // If no check-in yet, or already booked, or clicking on/before current check-in: start new check-in if (!checkIn || checkOut || day.date.day <= checkIn.day) { setCheckIn(day.date); setCheckOut(null); } else { // Pick is after checkIn: set as check-out setCheckOut(day.date); } }; const handleReset = () => { setCheckIn(null); setCheckOut(null); }; return ( Hotel Booking — June 2026 Season: Jun 5 – Jun 25 · Max stay: 7 nights · Closed Mondays {checkIn ? checkOut ? `Booked: Jun ${checkIn.day} – Jun ${checkOut.day}` : `Check-in: Jun ${checkIn.day} (pick check-out)` : 'Pick a check-in date'} {checkIn && (