// Multi-step booking modal const { useState: useStateBk, useEffect: useEffectBk, useMemo: useMemoBk } = React; function BookingModal({ onClose, lang, prefillTopic }) { const [step, setStep] = useStateBk(0); const [picked, setPicked] = useStateBk(null); const [date, setDate] = useStateBk(null); const [time, setTime] = useStateBk(null); const [calMonth, setCalMonth] = useStateBk(() => { const d = new Date(); return { y: d.getFullYear(), m: d.getMonth() }; }); const [form, setForm] = useStateBk({ name: '', email: '', phone: '', topic: prefillTopic || '' }); // ESC close useEffectBk(() => { const h = (e) => { if (e.key === 'Escape') onClose(); }; document.addEventListener('keydown', h); document.body.style.overflow = 'hidden'; return () => { document.removeEventListener('keydown', h); document.body.style.overflow = ''; }; }, [onClose]); const labels = lang === 'en' ? { title: 'Book a session', step1: 'Choose session', step2: 'Pick date & time', step3: 'Your details', step4: 'Confirmed', back: 'Back', next: 'Next', confirm: 'Confirm booking', name: 'Full name', email: 'Email', phone: 'Phone (with country code)', topic: 'What would you like to work on?', booked: 'See you then.', bookedSub: "You'll receive a calendar invite and meeting link by email.", callback: 'Our team will call you back shortly to confirm your booking.', ticketSession: 'Session', ticketDate: 'Date', ticketTime: 'Time', ticketName: 'Name', ticketRef: 'Ref', closeIt: 'Close', empty: 'Pick a date and time to continue' } : { title: 'സെഷൻ ബുക്ക് ചെയ്യൂ', step1: 'സെഷൻ തിരഞ്ഞെടുക്കൂ', step2: 'തീയതിയും സമയവും', step3: 'വിശദാംശങ്ങൾ', step4: 'സ്ഥിരീകരിച്ചു', back: 'പിന്നോട്ട്', next: 'അടുത്തത്', confirm: 'ബുക്കിംഗ് സ്ഥിരീകരിക്കൂ', name: 'പേര്', email: 'ഇമെയിൽ', phone: 'ഫോൺ (രാജ്യ കോഡ് സഹിതം)', topic: 'എന്തിൽ പ്രവർത്തിക്കണം?', booked: 'കാണാം.', bookedSub: 'ഇമെയിലിൽ കലണ്ടർ ക്ഷണവും മീറ്റിംഗ് ലിങ്കും ലഭിക്കും.', callback: 'ബുക്കിംഗ് സ്ഥിരീകരിക്കാൻ ഞങ്ങളുടെ ടീം ഉടൻ നിങ്ങളെ തിരികെ വിളിക്കും.', ticketSession: 'സെഷൻ', ticketDate: 'തീയതി', ticketTime: 'സമയം', ticketName: 'പേര്', ticketRef: 'റഫ്', closeIt: 'അടയ്ക്കൂ', empty: 'തുടരാൻ തീയതിയും സമയവും തിരഞ്ഞെടുക്കൂ' }; const stepNames = [labels.step1, labels.step2, labels.step3, labels.step4]; // Calendar const today = new Date(); today.setHours(0,0,0,0); const daysInMonth = new Date(calMonth.y, calMonth.m + 1, 0).getDate(); const firstDow = new Date(calMonth.y, calMonth.m, 1).getDay(); const monthName = new Date(calMonth.y, calMonth.m, 1).toLocaleString(lang === 'en' ? 'en' : 'ml', { month: 'long', year: 'numeric' }); const dowLabels = lang === 'en' ? ['Su','Mo','Tu','We','Th','Fr','Sa'] : ['ഞാ','തി','ചൊ','ബു','വ്യാ','വെ','ശ']; const slots = ['10:00', '11:30', '14:00', '15:30', '17:00', '18:30', '20:00', '21:30']; const canStep1 = !!picked; const canStep2 = !!date && !!time; const canStep3 = form.name.trim() && form.email.includes('@') && form.phone.trim().length >= 6; const refCode = useMemoBk(() => 'JB-' + Math.random().toString(36).slice(2, 8).toUpperCase(), []); const dateStr = date ? new Date(date.y, date.m, date.d).toLocaleDateString(lang === 'en' ? 'en-IN' : 'ml-IN', { weekday: 'short', day: 'numeric', month: 'long', year: 'numeric' }) : ''; return (
{ if (e.target.classList.contains('modal-back')) onClose(); }}>
{step < 3 ? `${labels.title}` : labels.step4}
{stepNames[step]}
{step < 3 && (
{[0,1,2].map((i) => (
i ? 'done' : ''}`}/> ))}
)}
{step === 0 && (
{window.SESSION_TYPES.map((s) => ( ))}
)} {step === 1 && (
{monthName}
{dowLabels.map((d, i) =>
{d}
)} {Array.from({ length: firstDow }).map((_, i) =>
)} {Array.from({ length: daysInMonth }, (_, i) => i + 1).map((d) => { const dt = new Date(calMonth.y, calMonth.m, d); const past = dt < today; const isToday = dt.getTime() === today.getTime(); const sel = date && date.y === calMonth.y && date.m === calMonth.m && date.d === d; return ( ); })}
{lang === 'en' ? 'Times shown in IST · Pick a slot' : 'IST സമയം · ഒരു സ്ലോട്ട് തിരഞ്ഞെടുക്കൂ'}
{slots.map((s) => ( ))}
)} {step === 2 && (
setForm({ ...form, name: e.target.value })} required/>
setForm({ ...form, email: e.target.value })} required/>
setForm({ ...form, phone: e.target.value })} placeholder="+91 9876543210"/>