const { useState, useEffect } = React;

function Header({ whatsappLink, onWhatsApp }) {
  const [scrolled, setScrolled] = useState(false);
  useEffect(() => {
    const onScroll = () => setScrolled(window.scrollY > 8);
    window.addEventListener('scroll', onScroll);
    return () => window.removeEventListener('scroll', onScroll);
  }, []);

  return (
    <header className={'hdr' + (scrolled ? ' hdr--scrolled' : '')}>
      <div className="hdr__inner">
        <a href="#topo" className="hdr__logo">
          <span style={{ color: 'var(--bac-blue)' }}>8</span>
          <span style={{ color: 'var(--bac-navy)' }}>BAC</span>
        </a>
        <nav className="hdr__nav">
          <a href="#problema">Problema</a>
          <a href="#metodo">Método</a>
          <a href="#sobre">Sobre</a>
          <a href="#faq">FAQ</a>
        </nav>
        <a href="#" className="hdr__cta" onClick={e => { e.preventDefault(); onWhatsApp(); }}>
          <i data-lucide="message-circle"></i>
          <span>Diagnóstico gratuito</span>
        </a>
      </div>
      <style>{`
        .hdr {
          position: sticky; top: 0; z-index: 50;
          background: #fff;
          border-bottom: 1px solid transparent;
          transition: all .22s var(--ease-out);
        }
        .hdr--scrolled {
          background: rgba(255,255,255,.92);
          backdrop-filter: blur(12px);
          -webkit-backdrop-filter: blur(12px);
          border-bottom-color: var(--line);
        }
        .hdr__inner {
          max-width: 1200px; margin: 0 auto;
          padding: 12px 20px;
          display: flex; align-items: center; justify-content: center; gap: 16px;
        }
        .hdr__logo {
          font-family: var(--font-display); font-weight: 900;
          font-size: 24px; line-height: 1; letter-spacing: -0.04em;
          text-decoration: none; flex-shrink: 0;
        }
        .hdr__nav {
          display: none;
          gap: 24px; margin-left: 20px; flex: 1;
        }
        .hdr__nav a {
          font-family: var(--font-sans); font-size: 14px; font-weight: 500;
          color: var(--ink-2); text-decoration: none;
        }
        .hdr__nav a:hover { color: var(--bac-blue); }
        .hdr__cta {
          display: none; align-items: center; gap: 6px;
          background: var(--bac-blue); color: #fff;
          font-family: var(--font-sans); font-weight: 600; font-size: 13px;
          padding: 10px 14px; border-radius: 8px;
          text-decoration: none; white-space: nowrap; flex-shrink: 0;
          transition: background .14s var(--ease-out);
        }
        .hdr__cta i { width: 15px; height: 15px; }
        .hdr__cta:hover { background: var(--bac-blue-700); }
        @media (min-width: 720px) {
          .hdr__inner { padding: 14px 24px; gap: 24px; justify-content: flex-start; }
          .hdr__logo { font-size: 26px; }
          .hdr__nav { display: flex; }
          .hdr__cta { display: inline-flex; font-size: 14px; padding: 10px 16px; }
          .hdr__cta i { width: 16px; height: 16px; }
        }
      `}</style>
    </header>
  );
}
