import { useState } from 'react'; import { Calendar as CalendarIcon, ChevronLeft, ChevronRight, Check, X } from 'lucide-react'; const SmartCalendar = ({ availability = [], bookings = [], onToggleDate }) => { const [currentDate, setCurrentDate] = useState(new Date()); const daysInMonth = (year, month) => new Date(year, month + 1, 0).getDate(); const firstDayOfMonth = (year, month) => new Date(year, month, 1).getDay(); const year = currentDate.getFullYear(); const month = currentDate.getMonth(); const monthNames = [ "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" ]; const prevMonth = () => setCurrentDate(new Date(year, month - 1, 1)); const nextMonth = () => setCurrentDate(new Date(year, month + 1, 1)); const days = []; const totalDays = daysInMonth(year, month); const startDay = firstDayOfMonth(year, month); // Padding for previous month for (let i = 0; i < startDay; i++) { days.push({ day: null, fullDate: null }); } // Current month days for (let i = 1; i <= totalDays; i++) { const fullDate = new Date(year, month, i).toISOString().split('T')[0]; const isAvailable = availability.includes(fullDate); const dayBookings = bookings.filter(b => b.date.startsWith(fullDate)); days.push({ day: i, fullDate, isAvailable, bookings: dayBookings }); } return (
Click a date to toggle