/* Wired CIO marketing site — Header (navigation organized around the four pillars) */
(function () {
  const DS = window.WiredCIODesignSystem_afa0a4;
  const I = window.WCIcons;
  const { Button, Logo, OUTCOMES } = DS;

  const OUTCOME_ICONS = { grow: I.Rocket, protect: I.ShieldCheck, automate: I.Burst, align: I.BadgeCheck };
  const ORDER = ['grow', 'protect', 'automate', 'align'];
  const svcSlug = (name) => String(name).toLowerCase().replace(/&/g, ' ').replace(/[^a-z0-9]+/g, '-').replace(/^-+|-+$/g, '');
  const svcHref = (name) => 'service.html?slug=' + svcSlug(name);
  const ABOUT = [
    { label: 'Why Wired CIO', blurb: 'The in-house IT leadership model, without the overhead.', href: '#' },
    { label: 'Wired CIO Team', blurb: 'Meet the strategists and engineers behind your IT.', href: 'team.html' },
    { label: 'Case Studies', blurb: 'Real outcomes from real Wired CIO engagements.', href: 'case-studies.html' },
    { label: 'Industries', blurb: 'Healthcare, legal, manufacturing, biotech, and SMB.', href: '#' },
    { label: 'Insights', blurb: 'Guides and articles from the Wired desk.', href: '#' },
  ];

  function OutcomeMenu({ k }) {
    const o = OUTCOMES[k] || {};
    const Ico = OUTCOME_ICONS[k];
    const services = o.services || [];
    return (
      <div style={{
        position: 'absolute', top: '100%', left: 0, marginTop: 6, width: 380,
        background: 'var(--surface-card)', border: '1px solid var(--border-subtle)',
        borderRadius: 'var(--radius-lg)', boxShadow: 'var(--shadow-lg)', padding: 20, zIndex: 60,
      }}>
        <div style={{ position: 'absolute', left: 0, right: 0, top: -8, height: 8 }} aria-hidden="true"></div>
        <div style={{ display: 'flex', alignItems: 'center', gap: 12, marginBottom: 12 }}>
          <span style={{ width: 40, height: 40, borderRadius: 'var(--radius-md)', background: o.accent, color: 'var(--wc-white)', display: 'inline-flex', alignItems: 'center', justifyContent: 'center', flexShrink: 0 }}><Ico size={20} /></span>
          <div>
            <div style={{ fontFamily: 'var(--font-display)', fontWeight: 800, fontSize: '0.8125rem', letterSpacing: '0.12em', textTransform: 'uppercase', color: 'var(--text-strong)' }}>{o.label}</div>
            <div style={{ fontFamily: 'var(--font-body)', fontSize: '0.8125rem', color: 'var(--text-muted)' }}>{o.tagline}</div>
          </div>
        </div>
        <p style={{ fontFamily: 'var(--font-body)', fontSize: '0.875rem', lineHeight: 1.5, color: 'var(--text-body)', margin: '0 0 14px' }}>{o.long}</p>
        <ul style={{ listStyle: 'none', margin: 0, padding: 0, display: 'grid', gap: 2 }}>
          {services.map((s) => (
            <li key={s}>
              <a href={svcHref(s)} style={{ display: 'flex', alignItems: 'center', gap: 9, padding: '8px 10px', borderRadius: 'var(--radius-sm)', textDecoration: 'none', color: 'var(--text-strong)', fontFamily: 'var(--font-body)', fontSize: '0.9375rem', fontWeight: 500 }}
                onMouseEnter={(e) => { e.currentTarget.style.background = `color-mix(in srgb, ${o.accent} 12%, transparent)`; }}
                onMouseLeave={(e) => { e.currentTarget.style.background = 'transparent'; }}>
                <span style={{ width: 5, height: 5, borderRadius: '50%', background: o.accent, flexShrink: 0 }} />
                {s}
              </a>
            </li>
          ))}
        </ul>
      </div>
    );
  }

  function AboutMenu() {
    return (
      <div style={{
        position: 'absolute', top: '100%', right: 0, marginTop: 6, width: 290,
        background: 'var(--surface-card)', border: '1px solid var(--border-subtle)',
        borderRadius: 'var(--radius-lg)', boxShadow: 'var(--shadow-lg)', padding: 10, zIndex: 60,
      }}>
        <div style={{ position: 'absolute', left: 0, right: 0, top: -8, height: 8 }} aria-hidden="true"></div>
        {ABOUT.map((a) => (
          <a key={a.label} href={a.href || '#'} style={{ display: 'block', padding: '11px 12px', borderRadius: 'var(--radius-sm)', textDecoration: 'none' }}
            onMouseEnter={(e) => { e.currentTarget.style.background = 'var(--wc-green-50)'; }}
            onMouseLeave={(e) => { e.currentTarget.style.background = 'transparent'; }}>
            <span style={{ display: 'block', fontFamily: 'var(--font-display)', fontWeight: 700, fontSize: '0.9375rem', color: 'var(--text-strong)' }}>{a.label}</span>
            <span style={{ display: 'block', fontFamily: 'var(--font-body)', fontSize: '0.8125rem', color: 'var(--text-muted)', marginTop: 2, lineHeight: 1.35 }}>{a.blurb}</span>
          </a>
        ))}
      </div>
    );
  }
  function SiteHeader({ onCta }) {
    const [y, setY] = React.useState(0);
    const [open, setOpen] = React.useState(false);
    const [menu, setMenu] = React.useState(null);
    const [, force] = React.useReducer((x) => x + 1, 0);

    React.useEffect(() => {
      const el = document.querySelector('[data-scroll]') || window;
      const onScroll = () => setY(el === window ? window.scrollY : el.scrollTop);
      onScroll();
      el.addEventListener('scroll', onScroll);
      return () => el.removeEventListener('scroll', onScroll);
    }, []);
    React.useEffect(() => {
      const h = () => force();
      window.addEventListener('tweakchange', h);
      return () => window.removeEventListener('tweakchange', h);
    }, []);

    // Header styling combines the transparent-overlay tweak with scroll position:
    // over the hero it is fully transparent with light nav; once the hero scrolls
    // past it becomes the translucent-white bar with dark nav.
    const rootEl = document.documentElement;
    const transparent = rootEl.getAttribute('data-headerstyle') === 'transparent';
    const dark = rootEl.getAttribute('data-scheme') === 'dark';
    const heroEl = document.querySelector('#top > section');
    const switchAt = transparent ? Math.max(120, (heroEl ? heroEl.offsetHeight : 640) - 76) : 12;
    const scrolled = y > switchAt;
    const overlay = transparent && !scrolled;
    const lightLogo = dark || overlay;
    const headerFg = overlay ? '#EAF3F2' : 'var(--text-strong)';

    return (
      <header style={{
        position: transparent ? 'fixed' : 'sticky', top: 0, left: 0, right: 0, zIndex: 50,
        ['--header-fg']: headerFg,
        background: overlay ? 'transparent' : (scrolled || transparent ? 'var(--surface-header)' : 'var(--surface-card)'),
        backdropFilter: (scrolled && !overlay) ? 'saturate(180%) blur(12px)' : 'none',
        borderBottom: '1px solid ' + (overlay ? 'transparent' : 'var(--border-subtle)'),
        transition: 'background var(--dur-base) var(--ease-standard), box-shadow var(--dur-base)',
        boxShadow: (scrolled && !overlay) ? 'var(--shadow-sm)' : 'none',
      }}>
        <div style={{ maxWidth: 'var(--container-max)', margin: '0 auto', padding: '0 var(--container-pad)', height: 76, display: 'flex', alignItems: 'center', justifyContent: 'space-between', gap: 20 }}>
          <a href="#top" className="wc-logo" style={{ display: 'flex', alignItems: 'center', flexShrink: 0 }}>
            <Logo variant="horizontal" theme="light" basePath="../../assets/logos" className="wc-logo-lightbg" style={{ height: 'var(--logo-h, 46px)', display: lightLogo ? 'none' : 'block' }} />
            <Logo variant="horizontal" theme="dark" basePath="../../assets/logos" className="wc-logo-darkbg" style={{ height: 'var(--logo-h, 46px)', display: lightLogo ? 'block' : 'none' }} />
          </a>

          <nav className="wc-desktop-nav" style={{ display: 'flex', gap: 2, alignItems: 'center' }} onMouseLeave={() => setMenu(null)}>
            {ORDER.map((k) => {
              const active = menu === k;
              const o = OUTCOMES[k] || {};
              return (
                <div key={k} style={{ position: 'relative' }} onMouseEnter={() => setMenu(k)}>
                  <button onClick={() => { const el = document.getElementById('explore'); if (el) { window.scrollTo({ top: el.getBoundingClientRect().top + window.scrollY - 70, behavior: 'smooth' }); } else { window.location.href = 'index.html#explore'; } }} style={{
                    display: 'inline-flex', alignItems: 'center', gap: 5, padding: '9px 13px', border: 'none', background: active ? `color-mix(in srgb, ${o.accent} 22%, transparent)` : 'transparent', cursor: 'pointer',
                    borderRadius: 'var(--radius-sm)', fontFamily: 'var(--font-display)', fontWeight: 700, fontSize: '0.8125rem', letterSpacing: '0.08em', textTransform: 'uppercase',
                    boxShadow: active ? `inset 0 -2px 0 ${o.accent}` : 'none',
                    transition: 'background var(--dur-fast), box-shadow var(--dur-fast), color var(--dur-fast)',
                    color: active ? o.accent : 'var(--header-fg, var(--text-strong))',
                  }}>
                    {o.label}<I.ChevronDown size={14} style={{ transform: active ? 'rotate(180deg)' : 'none', transition: 'transform var(--dur-fast)' }} />
                  </button>
                  {active ? <OutcomeMenu k={k} /> : null}
                </div>
              );
            })}
            <span style={{ width: 1, height: 22, background: 'var(--border-subtle)', margin: '0 8px' }} />
            <div style={{ position: 'relative' }} onMouseEnter={() => setMenu('about')}>
              <button style={{
                display: 'inline-flex', alignItems: 'center', gap: 5, padding: '9px 13px', border: 'none', cursor: 'pointer',
                background: menu === 'about' ? 'var(--wc-green-50)' : 'transparent', borderRadius: 'var(--radius-sm)',
                fontFamily: 'var(--font-body)', fontWeight: 600, fontSize: '0.875rem',
                color: menu === 'about' ? 'var(--wc-green-700)' : 'var(--header-fg, var(--text-strong))',
              }}>
                About<I.ChevronDown size={14} style={{ transform: menu === 'about' ? 'rotate(180deg)' : 'none', transition: 'transform var(--dur-fast)' }} />
              </button>
              {menu === 'about' ? <AboutMenu /> : null}
            </div>
          </nav>

          <div className="wc-desktop-nav" style={{ display: 'flex', alignItems: 'center', gap: 14, flexShrink: 0 }}>
            <Button size="sm" onClick={onCta}>Book a Strategy Call</Button>
          </div>

          <button className="wc-mobile-toggle" onClick={() => setOpen(!open)} aria-label="Menu" style={{ display: 'none', border: 'none', background: 'transparent', cursor: 'pointer', color: 'var(--text-strong)' }}>
            {open ? <I.X size={26} /> : <I.Menu size={26} />}
          </button>
        </div>

        {open ? (
          <div className="wc-mobile-menu" style={{ borderTop: '1px solid var(--border-subtle)', padding: '12px var(--container-pad) 20px', background: 'var(--surface-card)' }}>
            {ORDER.map((k) => {
              const o = OUTCOMES[k] || {};
              return (
              <a key={k} href="#explore" style={{ display: 'flex', alignItems: 'center', gap: 10, padding: '12px 4px', fontFamily: 'var(--font-display)', fontWeight: 700, letterSpacing: '0.06em', textTransform: 'uppercase', fontSize: '0.875rem', color: 'var(--text-strong)', textDecoration: 'none', borderBottom: '1px solid var(--wc-gray-100)' }}>
                <span style={{ width: 7, height: 7, borderRadius: '50%', background: o.accent }} />{o.label}
                <span style={{ fontFamily: 'var(--font-body)', fontWeight: 500, textTransform: 'none', letterSpacing: 0, fontSize: '0.8125rem', color: 'var(--text-muted)' }}>{o.tagline}</span>
              </a>
            ); })}
            {ABOUT.map((a) => <a key={a.label} href={a.href || '#'} style={{ display: 'block', padding: '12px 4px', fontFamily: 'var(--font-body)', fontWeight: 600, color: 'var(--text-strong)', textDecoration: 'none', borderBottom: '1px solid var(--wc-gray-100)' }}>{a.label}</a>)}
            <div style={{ marginTop: 14 }}><Button fullWidth onClick={onCta}>Book a Strategy Call</Button></div>
          </div>
        ) : null}
      </header>
    );
  }

  window.WCKit = Object.assign(window.WCKit || {}, { SiteHeader });
})();
