const SCOPE_OPTS = ['Custom Software', 'AI Voice & Chat Agents', 'Business Process Automation', 'Digital Marketing'];

function ScopeCTA() {
  const { Chip, Input, Textarea, Button, Icon, Badge } = DS;
  const wide = useMedia('(min-width: 1040px)');
  const [sel, setSel] = React.useState(['Business Process Automation']);
  const [brief, setBrief] = React.useState('');
  const [email, setEmail] = React.useState('');
  const [name, setName] = React.useState('');
  const [phone, setPhone] = React.useState('');
  const [err, setErr] = React.useState({});
  const [done, setDone] = React.useState(false);
  const toggle = (o) => setSel(sel.includes(o) ? sel.filter((x) => x !== o) : [...sel, o]);
  const submit = (e) => {
    e.preventDefault();
    const e2 = {};
    if (!name.trim()) e2.name = 'Enter your name';
    if (phone.replace(/\D/g, '').length < 10) e2.phone = 'Enter a valid phone number';
    if (!/^\S+@\S+\.\S+$/.test(email)) e2.email = 'Enter a valid email';
    if (!brief.trim()) e2.brief = 'Tell us briefly what you want';
    setErr(e2);
    if (!Object.keys(e2).length) setDone(true);
  };
  return (
    <section id="scope" style={{ padding: `${wide ? 96 : 56}px 0`, background: 'transparent' }}>
      <Container>
        <ScrollRise from={80} scaleFrom={0.92}><DepthStack dark radius={24} offset={14} inset={24}>
          <div style={{ position: 'relative', background: 'var(--yk-indigo)', boxShadow: '0 30px 60px -24px rgba(30,27,75,.55)', borderRadius: 24, overflow: 'hidden', padding: wide ? 56 : 28, display: 'grid', gridTemplateColumns: wide ? 'minmax(0,.9fr) minmax(0,1.1fr)' : 'minmax(0,1fr)', gap: wide ? 56 : 32 }}>
            <span aria-hidden style={{ position: 'absolute', left: 0, right: 0, top: 0, height: 2, background: 'var(--yk-gradient-h)' }} />
            <div aria-hidden style={{ position: 'absolute', inset: 0, backgroundImage: 'linear-gradient(rgba(233,231,255,.06) 1px, transparent 1px), linear-gradient(90deg, rgba(233,231,255,.06) 1px, transparent 1px)', backgroundSize: '48px 48px', pointerEvents: 'none' }} />
            <div style={{ position: 'relative', display: 'flex', flexDirection: 'column', gap: 16 }}>
              <span style={{ font: '600 12px var(--font-body)', letterSpacing: '.08em', textTransform: 'uppercase', color: 'var(--yk-sky)' }}>Scope your system</span>
              <h2 style={{ font: `600 ${wide ? 38 : 30}px/1.15 var(--font-display)`, letterSpacing: '-.025em', color: '#fff' }}>Tell us the workflow. We'll come back with an architecture.</h2>
              <p style={{ font: '400 16px/1.6 var(--font-body)', color: 'var(--text-on-dark-muted)' }}>A 30-minute call with an engineer, not a sales script. You'll leave with a rough system diagram and the questions we'd need answered to quote.</p>
              <ul style={{ listStyle: 'none', padding: 0, margin: '8px 0 0', display: 'grid', gap: 10 }}>
                {['Reviewed by an engineer within one business day', 'NDA available before the call', 'No obligation to proceed'].map((x) => <li key={x} style={{ display: 'flex', gap: 10, font: '400 14px var(--font-body)', color: '#E9E7FF' }}><Icon name="check" size={17} color="var(--yk-sky)" />{x}</li>)}
              </ul>
            </div>
            <div style={{ position: 'relative', background: 'rgba(255,255,255,.06)', backdropFilter: 'blur(14px)', WebkitBackdropFilter: 'blur(14px)', boxShadow: '0 1px 0 rgba(255,255,255,.08) inset', border: '1px solid rgba(233,231,255,.16)', borderRadius: 16, padding: wide ? 28 : 20 }}>
              {!done ? (
                <form onSubmit={submit} style={{ display: 'grid', gap: 16 }} noValidate>
                  <div style={{ display: 'grid', gridTemplateColumns: 'repeat(auto-fit, minmax(200px, 1fr))', gap: 14 }}>
                    <Input dark label="Full name" icon="user" value={name} onChange={(e) => setName(e.target.value)} placeholder="Your name" error={err.name} />
                    <Input dark label="Phone number" icon="phone" type="tel" value={phone} onChange={(e) => setPhone(e.target.value)} placeholder="+91 98765 43210" error={err.phone} />
                  </div>
                  <Input dark label="Email" icon="mail" type="email" value={email} onChange={(e) => setEmail(e.target.value)} placeholder="you@company.com" error={err.email} />
                  <Textarea dark label="What do you want to build or automate?" rows={3} value={brief} onChange={(e) => setBrief(e.target.value)} placeholder="e.g. Orders arrive by WhatsApp and email, and two people re-key them into our ERP." error={err.brief} />
                  <Button type="submit" size="lg" arrow fullWidth>Request Architecture Call</Button>
                </form>
              ) : (
                <div style={{ display: 'grid', gap: 16, animation: 'yk-fade-up .45s cubic-bezier(.22,1,.36,1) both' }}>
                  <span style={{ width: 44, height: 44, borderRadius: 12, display: 'grid', placeItems: 'center', background: 'rgba(6,182,212,.14)', color: 'var(--yk-sky)' }}><Icon name="check" size={22} /></span>
                  <h3 style={{ font: '600 22px/1.3 var(--font-display)', color: '#fff' }}>Request received</h3>
                  <p style={{ font: '400 15px/1.6 var(--font-body)', color: 'var(--text-on-dark-muted)' }}>Thanks, <span style={{ color: '#fff', fontWeight: 500 }}>{name.trim().split(' ')[0]}</span>. An engineer will contact you at <span style={{ color: '#fff', fontWeight: 500 }}>{email}</span> or <span style={{ color: '#fff', fontWeight: 500 }}>{phone}</span> within one business day.</p>
                  <div style={{ border: '1px solid rgba(233,231,255,.14)', borderRadius: 12, padding: 14, display: 'grid', gap: 10 }}>
                    <MonoLabel color="var(--text-on-dark-muted)">SCOPE · REF YK-{String(Math.abs(email.length * 7919) % 10000).padStart(4, '0')}</MonoLabel>
                    {brief && <p style={{ font: '400 13px/1.55 var(--font-body)', color: '#E9E7FF' }}>"{brief}"</p>}
                  </div>
                  <Button variant="outline-inverse" onClick={() => { setDone(false); setEmail(''); setBrief(''); setName(''); setPhone(''); }}>Submit another request</Button>
                </div>
              )}
            </div>
          </div>
        </DepthStack></ScrollRise>
      </Container>
    </section>
  );
}

function Footer() {
  const { Logo } = DS;
  const cols = [
    ['Services', ['Custom Software', 'AI Agents', 'Ops Automation', 'Digital Marketing']],
    ['Blueprints', ['Voice Qualification', 'Follow-Up Engine', 'Ops Dashboard', 'Approval Workflow']],
    ['Company', ['How We Build', 'Engagement Models', 'FAQ']],
    ['Contact', ['hello@yantrrk.com', 'Book a Discovery Call', 'LinkedIn']],
  ];
  return (
    <footer style={{ background: 'var(--yk-indigo)', color: '#fff', paddingTop: 72 }}>
      <Container>
        <div style={{ display: 'grid', gridTemplateColumns: 'repeat(auto-fit, minmax(160px, 1fr))', gap: 40 }}>
          <div style={{ gridColumn: 'span 2', minWidth: 0, display: 'flex', flexDirection: 'column', gap: 18 }}>
            <Logo base="../../" theme="dark" height={34} style={{ alignSelf: 'flex-start', width: 'auto', maxWidth: '100%' }} />
            <span style={{ font: '500 12px var(--font-body)', letterSpacing: '.22em', textTransform: 'uppercase', color: '#C7C4F2' }}>Automate • Connect • Grow</span>
            <p style={{ font: '400 14px/1.6 var(--font-body)', color: 'var(--text-on-dark-muted)', maxWidth: 320 }}>Custom software, AI communication agents and operations automation, engineered for teams that need to stay in control.</p>
          </div>
          {cols.map(([h, ls]) => (
            <div key={h}>
              <div style={{ font: '600 13px var(--font-body)', color: '#fff', marginBottom: 14 }}>{h}</div>
              <ul style={{ listStyle: 'none', margin: 0, padding: 0, display: 'grid', gap: 10 }}>{ls.map((l) => <li key={l}><a href="#" onClick={(e) => e.preventDefault()} style={{ font: '400 14px var(--font-body)', color: 'var(--text-on-dark-muted)' }} onMouseEnter={(e) => (e.currentTarget.style.color = '#fff')} onMouseLeave={(e) => (e.currentTarget.style.color = '')}>{l}</a></li>)}</ul>
            </div>
          ))}
        </div>
        <div style={{ marginTop: 56, padding: '22px 0 28px', borderTop: '1px solid rgba(233,231,255,.12)', display: 'flex', justifyContent: 'space-between', gap: 16, flexWrap: 'wrap', font: '400 13px var(--font-body)', color: '#A9A5DB' }}>
          <span>© 2026 Yantrrk. All rights reserved.</span>
          <span style={{ display: 'flex', gap: 20 }}><span>Privacy</span><span>Terms</span></span>
        </div>
      </Container>
    </footer>
  );
}

Object.assign(window, { ScopeCTA, Footer });
