// Shared bits: Nav, Footer, scroll reveal hook, cursor blob
const { useEffect, useRef, useState, useMemo } = React;

function useReveal(){
  useEffect(() => {
    const els = document.querySelectorAll('.reveal');
    const io = new IntersectionObserver((entries) => {
      entries.forEach(e => { if (e.isIntersecting) { e.target.classList.add('in'); io.unobserve(e.target); } });
    }, { threshold: 0.12 });
    els.forEach(el => io.observe(el));
    return () => io.disconnect();
  }, []);
}

function CursorBlob(){
  useEffect(() => {
    const blob = document.querySelector('.cursor-blob');
    if (!blob) return;
    let x = window.innerWidth/2, y = window.innerHeight/2, tx = x, ty = y, raf;
    const move = (e) => { tx = e.clientX; ty = e.clientY; document.body.classList.add('cursor-on'); };
    const leave = () => document.body.classList.remove('cursor-on');
    const loop = () => {
      x += (tx - x) * 0.12; y += (ty - y) * 0.12;
      blob.style.transform = `translate(${x}px, ${y}px) translate(-50%,-50%)`;
      raf = requestAnimationFrame(loop);
    };
    window.addEventListener('mousemove', move);
    window.addEventListener('mouseleave', leave);
    loop();
    return () => { window.removeEventListener('mousemove', move); cancelAnimationFrame(raf); };
  }, []);
  return <div className="cursor-blob" aria-hidden="true" />;
}

function Brand({light=false, variant='v1'}){
  const color = light ? 'var(--ink)' : 'var(--paper)';
  const accent = variant === 'v2' ? 'oklch(30% 0.08 220)' : variant === 'v3' ? '#FF6A3D' : '#4FB9E0';
  return (
    <a className="nav__brand" href="index.html" style={{color, '--logo-accent': accent, display:'inline-flex'}} aria-label="Get Visible — home">
      <svg className="nav__brand-lockup" viewBox="105 215 395 75" style={{height:28, width:'auto', display:'block', color}} aria-hidden="true">
        {/* mark — dark half uses currentColor (adapts to bg), accent half uses logo accent */}
        <path fill="currentColor" d="M160.9,263.1c-9,7.5-23.4,8.9-32.8,8.1,6.1,7.5,15.2,11.6,24.3,11.1,3.9-5.6,6.8-12.4,8.5-19.2Z"/>
        <path fill="currentColor" d="M147,267.4c-11.1-4.5-19.9-16.7-24.3-25.5-3.1,8.9-1.7,19,3.6,26.9,6.8.8,14.1.3,20.7-1.4Z"/>
        <path fill="currentColor" d="M136,257c-2.1-12,3.5-25.6,8.6-33.6-9.2,1.4-16.9,7.4-20.7,15.7,2.9,6.4,7.2,12.7,12.2,17.8h-.1Z"/>
        <path fill="currentColor" d="M138.9,242.3c9-7.5,23.4-8.8,32.8-8.1-6.1-7.5-15.2-11.6-24.3-11.1-3.9,5.6-6.8,12.4-8.5,19.2h0Z"/>
        <path fill={accent} d="M152.8,238.1c11.1,4.5,19.9,16.7,24.3,25.5,3.1-8.9,1.7-19-3.6-26.9-6.8-.8-14.1-.3-20.7,1.4Z"/>
        <path fill={accent} d="M163.8,248.5c2.1,12-3.5,25.6-8.6,33.6,9.2-1.4,16.9-7.4,20.7-15.7-2.9-6.4-7.2-12.7-12.2-17.8h.1Z"/>
        {/* GET (uses currentColor — adapts to background) */}
        <g fill="currentColor">
          <path d="M232,241.1v3.1c-.2,2.3-.8,4.4-1.8,6.3-1,1.9-2.4,3.6-4,4.9-1.6,1.4-3.5,2.5-5.6,3.3s-4.3,1.2-6.6,1.2-4.9-.5-7.2-1.5c-2.2-1-4.2-2.3-5.9-4-1.7-1.7-3.1-3.7-4-5.9-1-2.3-1.5-4.6-1.5-7.2s.5-4.9,1.5-7.2c.5-1.1,1.1-2.2,1.7-3.2.7-1,1.4-1.9,2.3-2.7,1.7-1.7,3.7-3,5.9-4s4.6-1.5,7.2-1.5,6.2.7,8.9,2.2c2.2,1.2,4.1,2.8,5.6,4.8.3.3.3.7.3,1.1s-.3.7-.7.9l-3.3,2c-.4.2-.7.3-1.1.2-.4,0-.8-.3-1.1-.6-.5-.5-.9-1-1.4-1.5s-1.1-.9-1.7-1.2c-1.7-1-3.6-1.6-5.5-1.6s-3.1.3-4.5,1c-1.5.7-2.7,1.6-3.7,2.7-1,1.1-1.9,2.4-2.5,3.9s-.9,3-.9,4.6.3,3.2.9,4.6c.7,1.5,1.5,2.8,2.5,3.9,1,1.1,2.2,2,3.7,2.6,1.4.7,2.9,1,4.5,1s2.4-.2,3.6-.6c1.1-.4,2.2-.9,3.1-1.6.9-.6,1.7-1.5,2.5-2.4.4-.6.7-1.1,1-1.7.2-.4.2-.7,0-1s-.5-.4-1-.4h-10.2c-.4,0-.8-.1-1.1-.4-.3-.3-.4-.7-.4-1.1v-3.1c0-.4.1-.8.4-1.1.3-.3.7-.4,1.1-.4h17.6c.4,0,.8.1,1.1.4.3.3.4.7.4,1.1Z"/>
          <path d="M244.6,231v5.9c0,.4.1.8.4,1.1.3.3.7.4,1.1.4h14.3c.4,0,.8.1,1.1.4.3.3.4.7.4,1.1v3.2c0,.4-.1.8-.4,1.1s-.7.4-1.1.4h-14.3c-.4,0-.8.1-1.1.4-.3.3-.4.7-.4,1.1v5.4c0,.4.1.8.4,1.1.3.3.7.4,1.1.4h16.5c.4,0,.8.1,1.1.4.3.3.4.7.4,1.1v3.1c0,.4-.1.8-.4,1.1-.3.3-.7.4-1.1.4h-23.3c-.4,0-.8-.1-1.1-.4s-.4-.7-.4-1.1v-32.8c0-.4.1-.8.4-1.1.3-.3.7-.4,1.1-.4h23.3c.4,0,.8.1,1.1.4.3.3.4.7.4,1.1v3c0,.4-.1.8-.4,1.1s-.7.4-1.1.4h-16.5c-.4,0-.8.1-1.1.4-.3.3-.4.7-.4,1.1Z"/>
          <path d="M293.3,229.4h-7.2c-.4,0-.8.1-1.1.4-.3.3-.4.7-.4,1.1v26.7c0,.4-.1.8-.4,1.1-.3.3-.7.4-1.1.4h-3.8c-.4,0-.8-.1-1.1-.4-.3-.3-.4-.7-.4-1.1v-26.7c0-.4-.1-.8-.4-1.1s-.7-.4-1.1-.4h-7.2c-.4,0-.8-.1-1.1-.4s-.4-.7-.4-1.1v-3c0-.4.1-.8.4-1.1s.7-.4,1.1-.4h24.3c.4,0,.8.1,1.1.4.3.3.4.7.4,1.1v3c0,.4-.1.8-.4,1.1s-.7.4-1.1.4Z"/>
        </g>
        {/* VISIBLE — accent */}
        <g fill={accent}>
          <path d="M329.9,224.8l-15.6,33.7c-.2.4-.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.1-1.1-.4-.3-.3-.4-.7-.4-1.1v-32.8c0-.4.1-.8.4-1.1s.7-.4,1.1-.4h23.3c.4,0,.8.1,1.1.4.3.3.4.7.4,1.1v3c0,.4-.1.8-.4,1.1s-.7.4-1.1.4h-16.5c-.4,0-.8.1-1.1.4-.3.3-.4.7-.4,1.1Z"/>
        </g>
      </svg>
    </a>
  );
}

function Nav({active, theme='dark', variant='v1'}){
  const light = theme === 'light';
  const home = (p) => p;
  return (
    <nav className="nav" style={light ? {background:'color-mix(in oklch, var(--paper) 82%, transparent)', borderColor:'var(--paper-rule)', color:'var(--ink)'} : {}}>
      <Brand light={light} variant={variant} />
      <div className="nav__links" style={light?{color:'var(--steel-500)'}:{}}>
        <a href={home('services.html', variant)} className={active==='services'?'is-active':''}>Services</a>
        <a href={home('case-study.html', variant)} className={active==='work'?'is-active':''}>Work</a>
        <a href="#approach">Approach</a>
        <a href="#insights">Insights</a>
        <a href="#about">About</a>
      </div>
      <a className="btn btn--primary" href="#contact" style={light?{background:'var(--ink)', color:'var(--paper)', borderColor:'var(--ink)'}:{}}>
        Get a proposal <span className="arrow">→</span>
      </a>
    </nav>
  );
}

function Footer(){
  return (
    <footer className="foot" id="contact">
      <div className="foot__grid">
        <div>
          <div style={{display:'inline-flex',alignItems:'center',gap:10,marginBottom:20}}>
            <span className="mark" style={{width:22,height:22,borderRadius:'50%',background:'conic-gradient(from 200deg, var(--cyan), #0A0D10 40%, var(--cyan-2) 70%, #0A0D10)',border:'1px solid var(--rule-strong)',display:'inline-block'}}/>
            <b className="display" style={{fontSize:18,color:'var(--paper)'}}>get<em style={{fontStyle:'normal',color:'var(--cyan)'}}>visible</em></b>
          </div>
          <div className="serif" style={{fontSize:28,lineHeight:1.15,color:'var(--paper)',maxWidth:'28ch',marginBottom:28}}>
            Growth engineered, not guessed. Let's find what's next for your pipeline.
          </div>
          <a className="btn btn--primary" href="mailto:hello@getvisible.com">
            hello@getvisible.com <span className="arrow">→</span>
          </a>
        </div>
        <div>
          <h5>Services</h5>
          <ul>
            <li><a href="services.html">Paid search</a></li>
            <li><a href="services.html">Search optimization</a></li>
            <li><a href="services.html">Paid social</a></li>
            <li><a href="services.html">Content</a></li>
            <li><a href="services.html">Analytics</a></li>
            <li><a href="services.html">Web design & dev</a></li>
          </ul>
        </div>
        <div>
          <h5>Company</h5>
          <ul>
            <li><a href="#">About</a></li>
            <li><a href="#">Work</a></li>
            <li><a href="#">Insights</a></li>
            <li><a href="#">Careers</a></li>
            <li><a href="#">Press</a></li>
          </ul>
        </div>
        <div>
          <h5>Office</h5>
          <ul>
            <li>1201 N Scottsdale Rd<br/>Scottsdale, AZ 85257</li>
            <li>+1 (480) 555&nbsp;0142</li>
            <li><a href="mailto:hello@getvisible.com">hello@getvisible.com</a></li>
          </ul>
        </div>
      </div>
      <div className="foot__bottom">
        <span>© 2026 Get Visible, LLC</span>
        <span>Transform · Transcend · Transact</span>
        <span>Privacy · Terms · Cookies</span>
      </div>
    </footer>
  );
}

// Tweaks — expose a few key knobs
const TWEAK_DEFAULTS = /*EDITMODE-BEGIN*/{
  "accentHue": 220,
  "displayFont": "Space Grotesk",
  "cursorBlob": true,
  "density": "comfortable"
}/*EDITMODE-END*/;

function applyTweaks(t){
  const r = document.documentElement;
  r.style.setProperty('--cyan', `oklch(78% 0.13 ${t.accentHue})`);
  r.style.setProperty('--cyan-2', `oklch(65% 0.14 ${t.accentHue})`);
  r.style.setProperty('--cyan-ink', `oklch(35% 0.08 ${t.accentHue})`);
  r.style.setProperty('--ff-display', `"${t.displayFont}", ui-sans-serif, system-ui, sans-serif`);
  document.body.dataset.density = t.density || 'comfortable';
  if (!t.cursorBlob) {
    const b = document.querySelector('.cursor-blob');
    if (b) b.style.display = 'none';
  } else {
    const b = document.querySelector('.cursor-blob');
    if (b) b.style.display = '';
  }
}

function Tweaks(){
  const [open, setOpen] = React.useState(false);
  const [vis, setVis] = React.useState(false);
  const [t, setT] = React.useState(TWEAK_DEFAULTS);

  React.useEffect(() => {
    const onMsg = (e) => {
      if (!e.data || typeof e.data !== 'object') return;
      if (e.data.type === '__activate_edit_mode') { setVis(true); setOpen(true); }
      if (e.data.type === '__deactivate_edit_mode') { setVis(false); setOpen(false); }
    };
    window.addEventListener('message', onMsg);
    window.parent.postMessage({type:'__edit_mode_available'}, '*');
    applyTweaks(TWEAK_DEFAULTS);
    return () => window.removeEventListener('message', onMsg);
  }, []);

  const update = (k, v) => {
    const next = {...t, [k]: v};
    setT(next); applyTweaks(next);
    window.parent.postMessage({type:'__edit_mode_set_keys', edits:{[k]: v}}, '*');
  };

  if (!vis) return null;
  return (
    <div className="tw">
      <button className="tw__toggle" onClick={() => setOpen(o => !o)}>
        <span className="mono">Tweaks</span>
        <span>{open ? '−' : '+'}</span>
      </button>
      {open && (
        <div className="tw__panel">
          <label className="tw__field">
            <span className="mono">Accent hue · {t.accentHue}</span>
            <input type="range" min="180" max="320" step="5" value={t.accentHue} onChange={e => update('accentHue', +e.target.value)}/>
          </label>
          <label className="tw__field">
            <span className="mono">Display font</span>
            <select value={t.displayFont} onChange={e => update('displayFont', e.target.value)}>
              <option>Space Grotesk</option>
              <option>Instrument Serif</option>
              <option>Geist</option>
            </select>
          </label>
          <label className="tw__field tw__row">
            <span className="mono">Cursor blob</span>
            <input type="checkbox" checked={t.cursorBlob} onChange={e => update('cursorBlob', e.target.checked)}/>
          </label>
          <label className="tw__field">
            <span className="mono">Density</span>
            <select value={t.density} onChange={e => update('density', e.target.value)}>
              <option value="compact">Compact</option>
              <option value="comfortable">Comfortable</option>
              <option value="spacious">Spacious</option>
            </select>
          </label>
        </div>
      )}
    </div>
  );
}

Object.assign(window, { useReveal, CursorBlob, Nav, Footer, Brand, Tweaks });
