/* global React */
const { useState: useStateNav, useEffect: useEffectNav } = React;

/* ---------- Inline SVG icons (no dependency on lucide loading) ---------- */
const SVG = (props) => (
  <svg
    xmlns="http://www.w3.org/2000/svg"
    width={props.size || 16}
    height={props.size || 16}
    viewBox="0 0 24 24"
    fill="none"
    stroke="currentColor"
    strokeWidth={props.stroke || 1.75}
    strokeLinecap="round"
    strokeLinejoin="round"
    aria-hidden="true"
    {...props.svgProps}
  >
    {props.children}
  </svg>
);

const GithubIcon = (p) => (
  <SVG {...p}>
    <path d="M15 22v-4a4.8 4.8 0 0 0-1-3.5c3 0 6-2 6-5.5.08-1.25-.27-2.48-1-3.5.28-1.15.28-2.35 0-3.5 0 0-1 0-3 1.5-2.64-.5-5.36-.5-8 0C6 2 5 2 5 2c-.3 1.15-.3 2.35 0 3.5A5.4 5.4 0 0 0 4 9c0 3.5 3 5.5 6 5.5-.39.49-.68 1.05-.85 1.65-.17.6-.22 1.23-.15 1.85v4" />
    <path d="M9 18c-4.51 2-5-2-7-2" />
  </SVG>
);
const LinkedInIcon = (p) => (
  <SVG {...p}>
    <path d="M16 8a6 6 0 0 1 6 6v7h-4v-7a2 2 0 0 0-2-2 2 2 0 0 0-2 2v7h-4v-7a6 6 0 0 1 6-6z" />
    <rect x="2" y="9" width="4" height="12" />
    <circle cx="4" cy="4" r="2" />
  </SVG>
);
const YouTubeIcon = (p) => (
  <SVG {...p}>
    <path d="M2.5 17a24.12 24.12 0 0 1 0-10 2 2 0 0 1 1.4-1.4 49.56 49.56 0 0 1 16.2 0A2 2 0 0 1 21.5 7a24.12 24.12 0 0 1 0 10 2 2 0 0 1-1.4 1.4 49.55 49.55 0 0 1-16.2 0A2 2 0 0 1 2.5 17" />
    <path d="m10 15 5-3-5-3z" />
  </SVG>
);
const ArrowUpRightIcon = (p) => (
  <SVG {...p}>
    <path d="M7 7h10v10" /><path d="M7 17 17 7" />
  </SVG>
);

function Nav() {
  const [scrolled, setScrolled] = useStateNav(false);

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

  return (
    <nav className={`at-nav${scrolled ? ' is-scrolled' : ''}`}>
      <a href="#" className="at-nav-brand" data-cursor-label="ansartech.net">
        <img src={(window.__resources && window.__resources.logoMark) || "assets/logo-mark.png"} alt="" />
        <span>AnsarTech</span>
        <span className="at-nav-brand-tag">V.2026</span>
      </a>

      <div className="at-nav-center">
        <a href="/case-studies">Case Studies</a>
        <a href="/services">Services</a>
        <a href="/about">About</a>
        <a href="/contact">Contact</a>
      </div>

      <div className="at-nav-right">
        <a
          href="https://github.com/zianansar"
          target="_blank"
          rel="noopener"
          className="at-btn at-btn--icon"
          aria-label="GitHub"
          data-cursor-label="github"
        >
          <GithubIcon size={16} data-comment-anchor="f9561e7c2c-i-32-11" />
        </a>
        <a
          href="https://linkedin.com/in/zian-ansar"
          target="_blank"
          rel="noopener"
          className="at-btn at-btn--icon"
          aria-label="LinkedIn"
          data-cursor-label="linkedin"
        >
          <LinkedInIcon size={16} />
        </a>
        <a
          href="https://www.youtube.com/@DiscoPandaAI"
          target="_blank"
          rel="noopener"
          className="at-btn at-btn--icon"
          aria-label="YouTube"
          data-cursor-label="youtube"
        >
          <YouTubeIcon size={16} />
        </a>
        <a href="/booking" className="at-btn at-btn--primary" data-cursor-label="book audit">
          Book a 30-min audit
          <ArrowUpRightIcon size={14} stroke={2} />
        </a>
      </div>
    </nav>
  );
}

window.Nav = Nav;
