import React, { useState } from 'react'; import { useOutletContext, Link } from 'react-router-dom'; import { User, Business, Service, Customer } from '../../types'; import { SERVICES, CUSTOMERS } from '../../mockData'; import { Check, ChevronLeft, Calendar, Clock, AlertTriangle, CreditCard } from 'lucide-react'; const BookingPage: React.FC = () => { const { user, business } = useOutletContext<{ user: User, business: Business }>(); const customer = CUSTOMERS.find(c => c.userId === user.id); const [step, setStep] = useState(1); const [selectedService, setSelectedService] = useState(null); const [selectedTime, setSelectedTime] = useState(null); const [bookingConfirmed, setBookingConfirmed] = useState(false); // Mock available times const availableTimes: Date[] = [ new Date(new Date().setHours(9, 0, 0, 0)), new Date(new Date().setHours(10, 30, 0, 0)), new Date(new Date().setHours(14, 0, 0, 0)), new Date(new Date().setHours(16, 15, 0, 0)), ]; const handleSelectService = (service: Service) => { if (business.requirePaymentMethodToBook && (!customer || customer.paymentMethods.length === 0)) { // Handled by the conditional rendering below, but could also be an alert. return; } setSelectedService(service); setStep(2); }; const handleSelectTime = (time: Date) => { setSelectedTime(time); setStep(3); }; const handleConfirmBooking = () => { // In a real app, this would send a request to the backend. setBookingConfirmed(true); setStep(4); }; const resetFlow = () => { setStep(1); setSelectedService(null); setSelectedTime(null); setBookingConfirmed(false); } const renderStepContent = () => { if (business.requirePaymentMethodToBook && (!customer || customer.paymentMethods.length === 0)) { return (

Payment Method Required

This business requires a payment method on file to book an appointment. Please add a card to your account before proceeding.

Go to Billing
) } switch (step) { case 1: // Select Service return (
{SERVICES.map(service => ( ))}
); case 2: // Select Time return (
{availableTimes.map(time => ( ))}
); case 3: // Confirmation return (

Confirm Your Booking

You are booking {selectedService?.name} for {selectedTime?.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' })}.

); case 4: // Success return (

Appointment Booked!

Your appointment for {selectedService?.name} at {selectedTime?.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' })} is confirmed.

Go to Dashboard
) default: return null; } }; return (
{step > 1 && step < 4 && ( )}

{step === 1 && "Step 1: Select a Service"} {step === 2 && "Step 2: Choose a Time"} {step === 3 && "Step 3: Confirm Details"} {step === 4 && "Booking Confirmed"}

{step === 1 && "Pick from our list of available services."} {step === 2 && `Available times for ${new Date().toLocaleDateString()}`} {step === 3 && "Please review your appointment details below."} {step === 4 && "We've sent a confirmation to your email."}

{renderStepContent()}
); }; export default BookingPage;