// About page — class-driven via styles.css

function AboutMain() {
  const [email, setEmail] = React.useState('');
  const [msg, setMsg] = React.useState('');
  const [err, setErr] = React.useState('');
  const [status, setStatus] = React.useState('idle');

  const sanitize = (s) => s.replace(/[<>]/g, '');

  const submit = async (e) => {
    e.preventDefault();
    if (status === 'sending') return;
    const emailTrim = email.trim();
    const msgTrim = sanitize(msg).trim();
    if (!emailTrim || !/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(emailTrim)) { setErr('Please enter a valid email address.'); return; }
    if (!msgTrim) { setErr('Please add a short message.'); return; }
    setErr(''); setStatus('sending');
    try {
      const res = await fetch('/api/contact', {
        method: 'POST',
        headers: { 'Content-Type': 'application/json', Accept: 'application/json' },
        body: JSON.stringify({ email: emailTrim, message: msgTrim, botcheck: '' }),
      });
      const data = await res.json().catch(() => ({}));
      if (res.ok && data && data.ok) { setStatus('sent'); setEmail(''); setMsg(''); }
      else if (res.status === 404) { setStatus('idle'); setErr('Contact form is only available on the deployed site.'); }
      else { setStatus('idle'); setErr((data && data.error) || 'Something went wrong. Please try again later.'); }
    } catch (_) { setStatus('idle'); setErr('Network error. Please try again later.'); }
  };

  return (
      <main className="about-main" style={{ maxWidth: 1440, width: '100%', margin: '0 auto', padding: '20px 40px 24px', display: 'grid', gridTemplateColumns: '1.5fr 1fr', gap: 48 }}>
        {/* LEFT — About */}
        <section className="about-section" style={{ display: 'grid', gridTemplateColumns: '200px 1fr', gap: 28, alignItems: 'start', minHeight: 0 }}>
          <div>
            <div style={{ width: 200, height: 232, border: '1px solid rgba(240,237,238,0.12)', background: 'var(--navy)', overflow: 'hidden' }}>
              <img src="assets/headshot-jason.jpg" alt="Jason Yu" style={{ width: '100%', height: '100%', objectFit: 'cover', display: 'block', filter: 'grayscale(15%)' }} />
            </div>
            <div style={{ marginTop: 14, fontSize: 10, letterSpacing: '0.2em', textTransform: 'uppercase', color: 'var(--text-faint)' }}>
              Based in Metro Detroit, MI
            </div>
            <div style={{ marginTop: 6, fontSize: 14, color: 'var(--text-soft)', lineHeight: 1.45 }}>
              Lead Product Designer<br />
              15+ years across enterprise, data and health
            </div>
            <a href="https://www.linkedin.com/in/jbirdux/" target="_blank" rel="noopener noreferrer" className="linkedin-chip">
              <svg width="14" height="14" viewBox="0 0 24 24" fill="currentColor" aria-hidden="true">
                <path d="M20.45 20.45h-3.55v-5.57c0-1.33-.02-3.04-1.85-3.04-1.86 0-2.14 1.45-2.14 2.95v5.66H9.36V9h3.41v1.56h.05c.47-.9 1.64-1.85 3.37-1.85 3.6 0 4.27 2.37 4.27 5.46v6.28zM5.34 7.43a2.06 2.06 0 1 1 0-4.12 2.06 2.06 0 0 1 0 4.12zM7.12 20.45H3.56V9h3.56v11.45zM22.22 0H1.77C.79 0 0 .77 0 1.72v20.56C0 23.23.79 24 1.77 24h20.45c.98 0 1.78-.77 1.78-1.72V1.72C24 .77 23.2 0 22.22 0z"/>
              </svg>
              <span style={{ letterSpacing: '0.04em' }}>LinkedIn — /in/jbirdux</span>
            </a>
            <a href="https://docs.google.com/document/d/1iuBrQmRfdN9-LQG3eZ6aCCqtJ7Ta53Z5mSNaE4jNNDk/preview" target="_blank" rel="noopener noreferrer" className="linkedin-chip" style={{ marginTop: 8 }}>
              <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true">
                <path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/>
                <polyline points="7 10 12 15 17 10"/>
                <line x1="12" y1="15" x2="12" y2="3"/>
              </svg>
              <span style={{ letterSpacing: '0.04em' }}>Download resume</span>
            </a>
          </div>

          <div style={{ display: 'flex', flexDirection: 'column', minHeight: 0 }}>
            <Eyebrow color="orange">About</Eyebrow>
            <h1 className="headline-xl" style={{ margin: '8px 0 12px', fontSize: 40 }}>Where complexity owes you clarity.</h1>
            <p className="body-serif" style={{ margin: '0 0 14px', fontSize: 17 }}>
              I'm a product designer who got interested in security by getting social-engineered in a video game as a kid. That sounds like a non-sequitur until you realize most of what I think about (trust systems, failure states, designing for skeptical users) traces back to the same instinct: what breaks this, and who gets hurt when it does.
            </p>
            <p className="body-serif" style={{ margin: '0 0 14px', fontSize: 17 }}>
              Gaming has quietly solved some of the hardest UX problems in existence: onboarding without tutorials, economy systems that balance trust and reward at scale, feedback loops that keep complex state legible under pressure. Those aren't gaming problems. They're product problems.
            </p>

            <div style={{ paddingTop: 14, marginTop: 16, borderTop: '1px solid var(--border-soft)' }}>
              <div style={{ fontSize: 10, letterSpacing: '0.2em', textTransform: 'uppercase', color: 'var(--orange)', fontWeight: 500, marginBottom: 8 }}>
                Design philosophy
              </div>
              <ul className="philosophy-grid" style={{ listStyle: 'none', margin: 0, padding: 0, display: 'grid', gridTemplateColumns: '1fr 1fr', gap: '14px 24px' }}>
                {[
                  ['Prevention over reaction', "Good design doesn't respond to failure; it makes certain failures structurally impossible."],
                  ['Constraint is the brief', "Limitations aren't obstacles to design around; they're the problem statement itself."],
                  ['Single responsibility', 'Every component, screen, and system should do one thing well enough that you never have to ask what it\u2019s for.'],
                  ['Legibility under pressure', "The real test of any interface isn't how it performs when everything is fine; it's how much it reveals when something isn't."],
                ].map(([t, d]) => (
                  <li key={t}>
                    <div style={{ fontFamily: 'var(--font-display)', fontSize: 16, fontWeight: 500, color: 'var(--platinum)', marginBottom: 4 }}>{t}</div>
                    <div style={{ fontSize: 14, lineHeight: 1.45, color: 'rgba(240,237,238,0.72)', textWrap: 'pretty' }}>{d}</div>
                  </li>
                ))}
              </ul>
            </div>

            <div style={{ paddingTop: 20, marginTop: 20, borderTop: '1px solid var(--border-soft)' }}>
              <p className="body-serif" style={{ margin: '0 0 18px', fontSize: 17 }}>
                Outside of design, I shoot barebow archery; a recurve style with no sights or stabilizers, just the bow and your own form. I like it for the same reason I like hard design problems: there are no shortcuts, only patience and small, honest adjustments. I’ve earned USA Archery’s red pin and took third place in a local club tournament.
              </p>
              <div className="archery-grid" style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', gap: 16 }}>
                {[
                  ['assets/archery-full-draw.jpg', 'Barebow, at full draw'],
                  ['assets/archery-third-place.jpg', 'Third Place at the Rising Phoenix Archery Galactic Tournament, 2025'],
                ].map(([src, cap]) => (
                  <figure key={src} style={{ margin: 0 }}>
                    <div style={{ aspectRatio: '3 / 4', border: '1px solid var(--border-soft)', overflow: 'hidden', background: 'var(--navy)' }}>
                      <img src={src} alt={cap} style={{ width: '100%', height: '100%', objectFit: 'cover', display: 'block' }} />
                    </div>
                    <figcaption style={{ marginTop: 8, fontSize: 14, lineHeight: 1.45, color: 'var(--text-soft)', textWrap: 'pretty' }}>{cap}</figcaption>
                  </figure>
                ))}
              </div>
            </div>
          </div>
        </section>

        {/* RIGHT — Contact form + On the record */}
        <aside style={{ display: 'flex', flexDirection: 'column', gap: 18, minHeight: 0 }}>
          <div id="contact" className="about-contact" style={{ background: 'var(--navy-card)', border: '1px solid var(--border-soft)', padding: '22px 24px 20px', display: 'flex', flexDirection: 'column' }}>
            <Eyebrow color="orange">Contact</Eyebrow>
            <h2 className="headline-md" style={{ margin: '8px 0 6px', fontSize: 28 }}>Let's talk.</h2>
            <p style={{ fontSize: 16, lineHeight: 1.5, color: 'var(--text-soft)', margin: '0 0 16px', textWrap: 'pretty' }}>
              Currently open to Senior and Lead Product Design roles. If you're building in AI, health tech, or security, I'd like to hear what you're working on.
            </p>

            <form onSubmit={submit} style={{ display: 'flex', flexDirection: 'column' }} noValidate>
              <input type="checkbox" name="botcheck" tabIndex={-1} autoComplete="off"
                style={{ position: 'absolute', left: '-9999px', opacity: 0, pointerEvents: 'none' }} aria-hidden="true" />
              <label htmlFor="email" className="field-label">Email</label>
              <input id="email" type="email" value={email} onChange={(e) => { setEmail(e.target.value); setErr(''); }}
                placeholder="you@company.com" autoComplete="email" className="field-input" />

              <label htmlFor="msg" className="field-label" style={{ marginTop: 12 }}>Message</label>
              <textarea id="msg" value={msg} onChange={(e) => { setMsg(sanitize(e.target.value)); setErr(''); }}
                placeholder="What are you working on?" rows={3} className="field-input" style={{ resize: 'none', minHeight: 70 }} />

              {err && <div className="field-error">{err}</div>}
              {status === 'sent' && (
                <div className="field-success">Message sent. I'll reply within a day, usually faster.</div>
              )}

              <div style={{ display: 'flex', alignItems: 'center', justifyContent: 'flex-end', marginTop: 12, gap: 14 }}>
                <button type="submit" disabled={status === 'sending'} className="btn-pill-upper"
                  style={{ fontSize: 14, fontWeight: 600, padding: '12px 22px', cursor: status === 'sending' ? 'wait' : 'pointer', opacity: status === 'sending' ? 0.7 : 1, transition: 'opacity 160ms ease' }}>
                  {status === 'sending' ? 'Sending…' : status === 'sent' ? 'Sent ✓' : 'Send message →'}
                </button>
              </div>
            </form>
          </div>

          <div>
            <div style={{ fontSize: 10, letterSpacing: '0.2em', textTransform: 'uppercase', color: 'var(--orange)', fontWeight: 500, marginBottom: 10 }}>
              On the record
            </div>
            <ul style={{ listStyle: 'none', margin: 0, padding: 0, display: 'flex', flexDirection: 'column', gap: 18 }}>
              {[
                ["This is the best laid out longer term thought process I've seen across the team. Most rush to solve for the now.", 'Jeff Huber', 'Director GuestXP and Technology, Ford'],
                ['His quick turnaround and strong work ethic helped our team deliver high quality product on schedule in a very high stakes high pressure environment with exceptional consistency.', 'Eric Christian', 'VP of Technology, XPO'],
              ].map(([quote, name, role]) => (
                <li key={name} style={{ borderLeft: '2px solid var(--orange)', paddingLeft: 12 }}>
                  <div style={{ fontFamily: 'var(--font-display)', fontSize: 14, lineHeight: 1.5, color: 'var(--platinum)', fontStyle: 'italic', marginBottom: 6, textWrap: 'pretty' }}>
                    “{quote}”
                  </div>
                  <div style={{ fontFamily: 'var(--font-ui)', fontSize: 13, fontWeight: 500, color: 'var(--platinum)', letterSpacing: '0.02em' }}>
                    {name}
                  </div>
                  <div style={{ fontFamily: 'var(--font-ui)', fontSize: 12, color: 'var(--text-soft)', letterSpacing: '0.04em', marginTop: 2 }}>
                    {role}
                  </div>
                </li>
              ))}
            </ul>
          </div>
        </aside>
      </main>
  );
}

function AboutPage() {
  return (
    <div className="page-shell">
      <TopNav active="About" variant="compact" />
      <AboutMain />
      <div style={{ marginTop: 'auto' }}>
        <SiteFooter />
      </div>
    </div>
  );
}

Object.assign(window, { AboutPage, AboutMain });
