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 (

{monthNames[month]} {year}

{['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'].map(d => (
{d}
))} {days.map((d, i) => (
d.fullDate && onToggleDate(d.fullDate)} className={` relative aspect-square flex flex-col items-center justify-center rounded-2xl cursor-pointer transition-all duration-300 group ${!d.day ? 'pointer-events-none' : 'hover:scale-95'} ${d.isAvailable ? 'bg-blue-50 text-blue-700 border border-blue-100' : 'text-gray-900 hover:bg-gray-50'} ${d.bookings.length > 0 ? 'ring-2 ring-indigo-600 ring-offset-2' : ''} `} > {d.day} {d.day && ( <>
{d.isAvailable ? : }
{d.bookings.length > 0 && (
)} {d.isAvailable && !d.bookings.length && (
)} )}
))}
Available
Booked

Click a date to toggle

); }; export default SmartCalendar;