// AveraTech — top navigation
const { useEffect, useState } = React;

function Nav() {
  const [scrolled, setScrolled] = useState(false);
  const [open, setOpen] = useState(false);

  useEffect(() => {
    const onScroll = () => setScrolled(window.scrollY > 12);
    onScroll();
    window.addEventListener('scroll', onScroll, { passive: true });
    return () => window.removeEventListener('scroll', onScroll);
  }, []);

  const links = [
    { href: '#servicos', label: 'Serviços' },
    { href: '#processo', label: 'Processo' },
    { href: '#tecnologias', label: 'Tecnologias' },
    { href: '#clientes', label: 'Clientes' },
    { href: '#sobre', label: 'Sobre' },
  ];

  return (
    <header className={"nav " + (scrolled ? "nav-scrolled" : "")}>
      <div className="container nav-inner">
        <a href="#top" className="nav-logo" aria-label="AveraTech home">
          <img src="assets/logo.png" alt="AveraTech" />
          <span className="nav-logo-tag">Tech</span>
        </a>
        <nav className="nav-links" aria-label="Principal">
          {links.map(l => (
            <a key={l.href} href={l.href}>{l.label}</a>
          ))}
        </nav>
        <div className="nav-cta">
          <span className="nav-status">
            <span className="nav-status-dot" />
            <span className="mono">Aceitando projetos · Q3</span>
          </span>
          <a href="#contato" className="btn btn-primary nav-btn">
            Falar com a gente
            <span className="arrow">→</span>
          </a>
        </div>
        <button className="nav-burger" onClick={() => setOpen(o => !o)} aria-label="Menu">
          <span /><span /><span />
        </button>
      </div>
      {open && (
        <div className="nav-mobile">
          {links.map(l => (
            <a key={l.href} href={l.href} onClick={() => setOpen(false)}>{l.label}</a>
          ))}
          <a href="#contato" className="btn btn-primary" onClick={() => setOpen(false)}>Falar com a gente →</a>
        </div>
      )}
    </header>
  );
}

window.Nav = Nav;
