/* global React, NA_DATA, NASite, naSupabase */ const { useState, useEffect } = React; // ============== TEAM ENQUIRY MODAL ============== function TeamEnquiryModal({ squad, onClose }) { const [status, setStatus] = useState('idle'); // 'idle' | 'sending' | 'sent' | 'error' const [errMsg, setErrMsg] = useState(''); const [form, setForm] = useState({ first_name: '', last_name: '', email: '', player_info: '', message: '' }); const [hp, setHp] = useState(''); // honeypot — must stay empty const startedAt = React.useRef(Date.now()); const set = (k, v) => setForm(f => ({ ...f, [k]: v })); if (!squad) return null; const submit = async (e) => { e.preventDefault(); setStatus('sending'); setErrMsg(''); // Spam guard — silently succeed without writing or starting a mandate. if (naSupabase.looksLikeSpam({ honeypot: hp, startedAt: startedAt.current })) { setStatus('sent'); return; } try { // Save the trial enquiry to Supabase so the coach app sees it. // No payment / Direct Debit at this stage — this is just an enquiry; // the coach follows up and sets up payment separately if it goes ahead. await naSupabase.submitEnquiry({ source: 'team_trial', squad_id: squad.id, first_name: form.first_name.trim(), last_name: form.last_name.trim(), email: form.email.trim(), player_info: form.player_info.trim(), message: form.message.trim(), }); setStatus('sent'); } catch (err) { console.warn('Trial enquiry failed:', err); setErrMsg(err.message || 'Could not send. Try again or email admin@nottinghamathletic.com.'); setStatus('error'); } }; const sent = status === 'sent'; const sending = status === 'sending'; return (
e.stopPropagation()}> {sent ? (

Message sent.

{squad.coach} will be in touch within a few days about trying out for {squad.name}.

) : ( <>
Enquire · {squad.name}

Message {squad.coach}.

Trials, late entry, or just a question — drop a line and the head coach will come back to you.

{/* Honeypot — hidden from humans, bots fill it. Leave empty. */}
set('first_name', e.target.value)} disabled={sending} />
set('last_name', e.target.value)} disabled={sending} />
set('email', e.target.value)} disabled={sending} />
set('player_info', e.target.value)} disabled={sending} />