import moment from 'moment' import type { CalendarEvent } from '../types' interface TimeSlotModalProps { selectedDate: Date newTimeSlot: { startTime: string endTime: string } existingEvents: CalendarEvent[] onTimeSlotChange: (timeSlot: { startTime: string; endTime: string }) => void onAdd: () => void onCancel: () => void isAdding?: boolean validationError?: string | null } export function TimeSlotModal({ selectedDate, newTimeSlot, existingEvents, onTimeSlotChange, onAdd, onCancel, isAdding = false, validationError = null }: TimeSlotModalProps) { const getEventsForDate = (date: Date) => { return existingEvents.filter(event => { const eventDate = new Date(event.start) return eventDate.toDateString() === date.toDateString() }) } // Validate time slot const isValid = () => { if (!newTimeSlot.startTime || !newTimeSlot.endTime) { return false } const [startHour, startMinute] = newTimeSlot.startTime.split(':').map(Number) const [endHour, endMinute] = newTimeSlot.endTime.split(':').map(Number) const startMinutes = startHour * 60 + startMinute const endMinutes = endHour * 60 + endMinute return startMinutes < endMinutes } return (
e.stopPropagation()}> {/* Close Button */}

Add Availability for {moment(selectedDate).format('MMMM D, YYYY')}

onTimeSlotChange({ ...newTimeSlot, startTime: e.target.value })} className={`w-full px-3 py-2 border rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500 dark:bg-gray-700 dark:text-white ${ validationError || !isValid() && newTimeSlot.startTime && newTimeSlot.endTime ? 'border-red-300 dark:border-red-600' : 'border-gray-300 dark:border-gray-600' }`} disabled={isAdding} />
onTimeSlotChange({ ...newTimeSlot, endTime: e.target.value })} className={`w-full px-3 py-2 border rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500 dark:bg-gray-700 dark:text-white ${ validationError || !isValid() && newTimeSlot.startTime && newTimeSlot.endTime ? 'border-red-300 dark:border-red-600' : 'border-gray-300 dark:border-gray-600' }`} disabled={isAdding} /> {(validationError || (!isValid() && newTimeSlot.startTime && newTimeSlot.endTime)) && (

{validationError || 'End time must be after start time'}

)}
{/* Show existing time slots for this date */} {getEventsForDate(selectedDate).length > 0 && (

Existing time slots:

{getEventsForDate(selectedDate).map(event => (
{moment(event.start).format('HH:mm')} - {moment(event.end).format('HH:mm')} ({event.title})
))}
)}
) }