// Enquiry modal — collects an enquiry (no direct booking) and emails the team const { useState: useStateBk, useEffect: useEffectBk, useMemo: useMemoBk } = React; function BookingModal({ onClose, lang, prefillTopic }) { // If opened from a specific "Bring Jishad to your stage" format, match it to // an interest so we can pre-select it and skip the "choose interest" step. const matchedInterest = (() => { const p = (prefillTopic || '').trim(); if (!p) return null; return (window.SESSION_TYPES || []).find(s => s.t === p || p.includes(s.t) || s.t.includes(p)) || null; })(); const [step, setStep] = useStateBk(matchedInterest ? 1 : 0); const [picked, setPicked] = useStateBk(matchedInterest ? matchedInterest.id : null); const [form, setForm] = useStateBk({ name: '', email: '', phone: '', topic: matchedInterest ? '' : (prefillTopic || '') }); const [sending, setSending] = useStateBk(false); const [submitError, setSubmitError] = useStateBk(''); const [hp, setHp] = useStateBk(''); // honeypot — must stay empty // 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: 'Enquiry', step1: 'What are you interested in?', step2: 'Your details', step3: 'Enquiry sent', back: 'Back', next: 'Next', confirm: 'Send enquiry', name: 'Full name', email: 'Email', phone: 'Phone (with country code)', topic: 'How can we help?', booked: 'Thank you!', bookedSub: 'Our team will contact you shortly.', callback: 'We usually get back within one working day.', ticketInterest: 'Interest', ticketName: 'Name', ticketRef: 'Ref', closeIt: 'Close', empty: 'Add your details to continue' } : { title: 'അന്വേഷണം', step1: 'എന്തിനെക്കുറിച്ചാണ് അന്വേഷണം?', step2: 'നിങ്ങളുടെ വിശദാംശങ്ങൾ', step3: 'അന്വേഷണം അയച്ചു', back: 'പിന്നോട്ട്', next: 'അടുത്തത്', confirm: 'അന്വേഷണം അയക്കൂ', name: 'പേര്', email: 'ഇമെയിൽ', phone: 'ഫോൺ (രാജ്യ കോഡ് സഹിതം)', topic: 'എങ്ങനെ സഹായിക്കാം?', booked: 'നന്ദി!', bookedSub: 'ഞങ്ങളുടെ ടീം ഉടൻ നിങ്ങളെ ബന്ധപ്പെടും.', callback: 'സാധാരണ ഒരു പ്രവൃത്തിദിവസത്തിനുള്ളിൽ ഞങ്ങൾ മറുപടി നൽകും.', ticketInterest: 'താൽപ്പര്യം', ticketName: 'പേര്', ticketRef: 'റഫ്', closeIt: 'അടയ്ക്കൂ', empty: 'തുടരാൻ വിശദാംശങ്ങൾ ചേർക്കൂ' }; const stepNames = [labels.step1, labels.step2, labels.step3]; // Interest options = a general option + the speaking / session formats. const interestOptions = useMemoBk(() => { const general = lang === 'en' ? { id: 'general', t: 'General enquiry', d: 'Not sure yet — I just want to get in touch.' } : { id: 'general', t: 'പൊതു അന്വേഷണം', d: 'ഉറപ്പില്ല — വെറുതെ ബന്ധപ്പെടണം.' }; return [general, ...(window.SESSION_TYPES || [])]; }, [lang]); const canStep1 = !!picked; const canStep2 = form.name.trim() && form.email.includes('@') && form.phone.trim().length >= 6; const refCode = useMemoBk(() => 'JB-' + Math.random().toString(36).slice(2, 8).toUpperCase(), []); const interestName = (interestOptions.find(s => s.id === picked) || {}).t || ''; // Send the enquiry to the server (send-booking.php → Resend), then show success. // Promise chain (not async/await) to stay safe under in-browser Babel. const submitEnquiry = () => { if (!canStep2 || sending) return; setSubmitError(''); setSending(true); let httpOk = false; fetch('send-booking.php', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ name: form.name.trim(), email: form.email.trim(), phone: form.phone.trim(), topic: form.topic.trim(), interest: interestName, ref: refCode, company: hp, // honeypot }), }) .then((res) => { httpOk = res.ok; return res.json().catch(() => ({})); }) .then((data) => { if (!httpOk || !data.ok) { throw new Error(data.error || (lang === 'en' ? 'Something went wrong. Please try again.' : 'എന്തോ കുഴപ്പം. വീണ്ടും ശ്രമിക്കൂ.')); } setStep(2); }) .catch((err) => { setSubmitError(err.message || (lang === 'en' ? 'Could not send. Please try again.' : 'അയക്കാനായില്ല. വീണ്ടും ശ്രമിക്കൂ.')); }) .then(() => setSending(false)); }; return (
{labels.bookedSub}