'use client'; import { useState } from 'react'; import { Calendar } from '@/components/ui/calendar'; import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card'; import { Button } from '@/components/ui/button'; import { Badge } from '@/components/ui/badge'; import { CalendarIcon, Clock, MapPin } from 'lucide-react'; const timeSlots = [ '09:00', '10:00', '11:00', '12:00', '13:00', '14:00', '15:00', '16:00', '17:00', '18:00', '19:00', '20:00', ]; const courts = [ { id: 'court-1', name: 'Court 1', isActive: true }, { id: 'court-2', name: 'Court 2', isActive: true }, ]; export function BookingCalendar() { const [selectedDate, setSelectedDate] = useState(new Date()); const [selectedSlot, setSelectedSlot] = useState(null); const [selectedCourt, setSelectedCourt] = useState(null); const formatDate = (date: Date) => { return date.toLocaleDateString('en-IE', { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric', }); }; const handleBooking = async () => { if (!selectedDate || !selectedSlot || !selectedCourt) { return; } try { const response = await fetch('/api/bookings', { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify({ courtId: selectedCourt, date: selectedDate.toISOString().split('T')[0], timeSlot: selectedSlot, }), }); const result = await response.json(); if (response.ok) { // Reset selections and show success setSelectedSlot(null); setSelectedCourt(null); // Show success message alert('Booking created successfully!'); } else { alert(result.error || 'Booking failed'); } } catch (error) { console.error('Booking error:', error); alert('An error occurred while creating the booking'); } }; return (
{/* Calendar */} Select Date Choose the date for your table tennis session date && setSelectedDate(date)} disabled={(date) => date < new Date() || date.getDay() === 0} // Disable past dates and Sundays className='rounded-md border' /> {/* Time Slots and Courts */} Available Slots {selectedDate ? formatDate(selectedDate) : 'Select a date first'} {/* Court Selection */}

Select Court

{courts.map((court) => ( ))}
{/* Time Slot Selection */}

Select Time

{timeSlots.map((time) => { const isBooked = Math.random() > 0.7; // Simulate some bookings return ( ); })}
{/* Booking Summary */} {selectedDate && selectedSlot && selectedCourt && (

Booking Summary

{formatDate(selectedDate)}
{selectedSlot} - {String(parseInt(selectedSlot.split(':')[0]) + 1).padStart(2, '0')} :00
{courts.find((c) => c.id === selectedCourt)?.name}
)}
); }