/* =========================================================
   SCG Growth Partners — Contact page
   ========================================================= */

function ContactForm() {
  const isMobile = useIsMobile();
  const [submitted, setSubmitted] = useState(false);
  const [sending, setSending] = useState(false);
  const [error, setError] = useState(null);
  const [form, setForm] = useState({ name:'', email:'', company:'', size:'11–50', title:'', notes:'' });
  const update = k => e => setForm({...form, [k]: e.target.value});

  const handleSubmit = async (e) => {
    e.preventDefault();
    setSending(true);
    setError(null);
    try {
      const res = await fetch(FORMSPREE_ENDPOINT, {
        method:'POST',
        headers:{'Content-Type':'application/json','Accept':'application/json'},
        body: JSON.stringify(form),
      });
      if (res.ok) { setSubmitted(true); }
      else { setError('Something went wrong. Email sam@scggrowth.com directly.'); }
    } catch { setError('Could not send. Email sam@scggrowth.com directly.'); }
    finally { setSending(false); }
  };

  if (submitted) {
    return (
      <Card padding={isMobile?32:56} style={{textAlign:'center'}}>
        <div style={{width:56, height:56, margin:'0 auto 20px', borderRadius:'50%', background:'var(--accent-soft)', color:'var(--accent)', display:'grid', placeItems:'center'}}><Icon.Check size={28}/></div>
        <h3 style={{fontFamily:'var(--font-serif)', fontSize:36, fontWeight:500, color:'var(--ink)', letterSpacing:'-0.018em', marginBottom:12}}>Got it.</h3>
        <p style={{fontSize:16, lineHeight:1.6, color:'var(--fg-3)', maxWidth:480, margin:'0 auto 28px'}}>
          We'll be in touch within one business day with two diagnostic-call times that work for you.
        </p>
        <Button kind="secondary" onClick={()=>{setSubmitted(false);setForm({name:'',email:'',company:'',size:'11–50',title:'',notes:''});}}>Send another</Button>
      </Card>
    );
  }

  const inputStyle = {
    fontFamily:'var(--font-sans)', fontSize:14, color:'var(--fg-1)',
    background:'var(--white)', border:'1px solid var(--slate-200)',
    borderRadius:'var(--r-2)', padding:'12px 14px', outline:'none', width:'100%', boxSizing:'border-box',
  };
  const labelStyle = { fontSize:12.5, fontWeight:600, color:'var(--fg-2)', marginBottom:7, display:'block' };

  return (
    <Card padding={isMobile?24:40}>
      {error && <div style={{marginBottom:16, padding:'12px 16px', background:'#fef2f2', border:'1px solid #fecaca', borderRadius:'var(--r-2)', fontSize:13.5, color:'#b91c1c'}}>{error}</div>}
      <form onSubmit={handleSubmit}>
        <div style={{display:'grid', gridTemplateColumns:isMobile?'1fr':'1fr 1fr', gap:16, marginBottom:16}}>
          <div><label style={labelStyle}>Name</label><input style={inputStyle} value={form.name} onChange={update('name')} placeholder="Jane Doe" required/></div>
          <div><label style={labelStyle}>Work email</label><input type="email" style={inputStyle} value={form.email} onChange={update('email')} placeholder="jane@company.com" required/></div>
          <div><label style={labelStyle}>Company</label><input style={inputStyle} value={form.company} onChange={update('company')} placeholder="Acme Inc."/></div>
          <div><label style={labelStyle}>Company size</label>
            <select style={inputStyle} value={form.size} onChange={update('size')}>
              <option>1–10</option><option>11–50</option><option>51–200</option><option>200–1,000</option><option>1,000+</option>
            </select>
          </div>
        </div>
        <div style={{marginBottom:16}}>
          <label style={labelStyle}>Job title</label>
          <input style={inputStyle} value={form.title} onChange={update('title')} placeholder="Founder / CEO / Head of Sales"/>
        </div>
        <div style={{marginBottom:28}}>
          <label style={labelStyle}>What's going on?</label>
          <textarea style={{...inputStyle, minHeight:120, fontFamily:'var(--font-sans)', resize:'vertical'}} rows={4} value={form.notes} onChange={update('notes')} placeholder="Where outbound is today, what you're trying to fix, anything else we should know."></textarea>
        </div>
        <div style={{display:'flex', alignItems:'center', justifyContent:isMobile?'stretch':'flex-end'}}>
          <Button kind="primary" size="md" type="submit" full={isMobile} iconRight={<Icon.ArrowRight size={14}/>}>{sending?'Sending...':'Send'}</Button>
        </div>
      </form>
    </Card>
  );
}

function ContactPage() {
  const isMobile = useIsMobile();
  return (
    <div data-screen-label="04 Contact">
      <Nav current="contact"/>
      <main style={{padding:isMobile?'48px 20px 48px':'72px 32px 64px'}}>
        <div style={{maxWidth:'var(--content-max)', margin:'0 auto'}}>
          <h1 style={{fontFamily:'var(--font-serif)', fontSize:isMobile?42:72, fontWeight:500, lineHeight:1.02, letterSpacing:'-0.022em', color:'var(--ink)', marginTop:0, marginBottom:isMobile?16:24, textWrap:'balance'}}>
            Start growing your outbound pipeline <span style={{color:'var(--slate-300)'}}>today.</span>
          </h1>
          <p style={{fontSize:isMobile?16:19, lineHeight:1.55, color:'var(--fg-2)', maxWidth:720, marginBottom:isMobile?40:64}}>
            The first 30 minutes are on us. We'll ask a handful of questions, look at your numbers if you have them handy, and tell you whether we're the right fit.
          </p>

          <div style={{display:'grid', gridTemplateColumns:isMobile?'1fr':'1fr 1.2fr', gap:isMobile?28:64, alignItems:'flex-start', marginBottom:isMobile?48:96}}>
            {/* What to expect — above form on mobile */}
            <div style={{order:isMobile?-1:1}}>
              <div style={{padding:isMobile?20:28, background:'var(--paper-2)', borderRadius:'var(--r-3)', border:'1px solid var(--border-1)'}}>
                <Eyebrow>What to expect</Eyebrow>
                <div style={{marginTop:18, display:'flex', flexDirection:'column', gap:14}}>
                  {[
                    'A 30-minute call within 24 hours of your inquiry',
                    'A handful of pointed questions on your motion, team, and number',
                    "A frank read on whether we're the right fit",
                    'No deck, no pitch, no follow-up cadence',
                  ].map((t,i)=>(
                    <div key={i} style={{display:'flex', alignItems:'flex-start', gap:10, fontSize:14, color:'var(--fg-2)', lineHeight:1.5}}>
                      <span style={{color:'var(--accent)', flexShrink:0, marginTop:2}}><Icon.Check size={16}/></span>
                      <span>{t}</span>
                    </div>
                  ))}
                </div>
              </div>
            </div>
            <ContactForm/>
          </div>

          <div style={{marginBottom:isMobile?24:32}}><ClientLogos variant="card"/></div>

          {/* Founders strip */}
          <div style={{padding:isMobile?'28px 20px':'40px 32px', background:'var(--bone)', border:'1px solid var(--border-1)', borderRadius:'var(--r-3)', display:'flex', flexDirection:isMobile?'column':'row', alignItems:isMobile?'flex-start':'center', justifyContent:'space-between', gap:isMobile?20:32}}>
            <div style={{display:'flex', alignItems:'center', gap:20}}>
              <div style={{display:'flex'}}>
                {['SS','GC'].map((init,i)=>(
                  <span key={i} style={{width:56, height:56, borderRadius:'50%', background:i===0?'var(--accent-soft)':'var(--paper-2)', color:i===0?'var(--accent-press)':'var(--fg-3)', display:'inline-grid', placeItems:'center', fontFamily:'var(--font-serif)', fontSize:20, fontWeight:500, marginLeft:i===0?0:-14, border:'3px solid var(--bone)', boxShadow:'var(--shadow-1)'}}>{init}</span>
                ))}
              </div>
              <div>
                <div style={{fontSize:15, fontWeight:600, color:'var(--ink)'}}>Sam Sansone & George Cunningham</div>
                <div style={{fontSize:13.5, color:'var(--fg-3)', marginTop:2}}>Both co-founders are on every diagnostic call.</div>
              </div>
            </div>
            <Button kind="secondary" href="/about" full={isMobile} iconRight={<Icon.ArrowRight size={14}/>}>Read their bios</Button>
          </div>
        </div>
      </main>
      <Footer/>
    </div>
  );
}

ReactDOM.createRoot(document.getElementById('root')).render(<ContactPage/>);
