/* global React */

// ============ Icon components ============
const Icon = {
  Arrow: (props) => (
    <svg className="arrow" {...props} viewBox="0 0 16 16" fill="none">
      <path d="M3 8h10m0 0-3.5-3.5M13 8l-3.5 3.5" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" strokeLinejoin="round"/>
    </svg>
  ),
  Check: () => (
    <svg width="14" height="14" viewBox="0 0 16 16" fill="none">
      <path d="M3 8.5 6.5 12 13 4.5" stroke="currentColor" strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round"/>
    </svg>
  ),
  Bolt: () => (
    <svg width="20" height="20" viewBox="0 0 24 24" fill="none">
      <path d="m13 3-9 11h7l-1 7 9-11h-7l1-7Z" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" strokeLinejoin="round"/>
    </svg>
  ),
  Shield: () => (
    <svg width="20" height="20" viewBox="0 0 24 24" fill="none">
      <path d="M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10Z" stroke="currentColor" strokeWidth="1.5" strokeLinejoin="round"/>
      <path d="m9 12 2 2 4-4" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" strokeLinejoin="round"/>
    </svg>
  ),
  Globe: () => (
    <svg width="20" height="20" viewBox="0 0 24 24" fill="none">
      <circle cx="12" cy="12" r="9" stroke="currentColor" strokeWidth="1.5"/>
      <path d="M3 12h18M12 3a14 14 0 0 1 0 18M12 3a14 14 0 0 0 0 18" stroke="currentColor" strokeWidth="1.5"/>
    </svg>
  ),
  Network: () => (
    <svg width="20" height="20" viewBox="0 0 24 24" fill="none">
      <circle cx="6" cy="6" r="2.5" stroke="currentColor" strokeWidth="1.5"/>
      <circle cx="18" cy="6" r="2.5" stroke="currentColor" strokeWidth="1.5"/>
      <circle cx="12" cy="18" r="2.5" stroke="currentColor" strokeWidth="1.5"/>
      <path d="M7.5 7.8 11 16M16.5 7.8 13 16" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round"/>
    </svg>
  ),
  Chart: () => (
    <svg width="20" height="20" viewBox="0 0 24 24" fill="none">
      <path d="M4 20V8m6 12V4m6 16v-8m6 8v-4" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round"/>
    </svg>
  ),
  Code: () => (
    <svg width="20" height="20" viewBox="0 0 24 24" fill="none">
      <path d="m8 8-5 4 5 4m8-8 5 4-5 4M14 4l-4 16" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" strokeLinejoin="round"/>
    </svg>
  ),
  Lock: () => (
    <svg width="20" height="20" viewBox="0 0 24 24" fill="none">
      <rect x="4" y="10" width="16" height="11" rx="2" stroke="currentColor" strokeWidth="1.5"/>
      <path d="M8 10V7a4 4 0 0 1 8 0v3" stroke="currentColor" strokeWidth="1.5"/>
    </svg>
  ),
  Refresh: () => (
    <svg width="20" height="20" viewBox="0 0 24 24" fill="none">
      <path d="M4 12a8 8 0 0 1 14-5.3M20 4v4h-4M20 12a8 8 0 0 1-14 5.3M4 20v-4h4" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" strokeLinejoin="round"/>
    </svg>
  ),
};

// ============ Wordmark ============
function Wordmark({ size = 22, accent = "#3B6BFF" }) {
  return (
    <span className="wordmark" style={{ fontSize: size }} aria-label="Rival">
      <svg width={size} height={size} viewBox="0 0 24 24" fill="none" style={{ marginRight: 2 }}>
        <path d="M4 20 L9 4 L14 4 L11 13 L20 13 L20 20 L4 20 Z" fill={accent}/>
        <path d="M9 13 L11 13 L11 20 L8 20 Z" fill="white"/>
      </svg>
      Rival
    </span>
  );
}

// ============ Nav ============
function Nav() {
  const [scrolled, setScrolled] = React.useState(false);
  React.useEffect(() => {
    const onScroll = () => setScrolled(window.scrollY > 20);
    window.addEventListener("scroll", onScroll, { passive: true });
    return () => window.removeEventListener("scroll", onScroll);
  }, []);

  return (
    <nav className={"nav " + (scrolled ? "nav-scrolled" : "")}>
      <div className="container nav-inner">
        <a href="#top"><Wordmark /></a>
        <div className="nav-links">
          <a href="#solutions" className="nav-link">Solutions</a>
          <a href="#methods" className="nav-link">Payment methods</a>
          <a href="#platform" className="nav-link">Platform</a>
          <a href="#developers" className="nav-link">Developers</a>
          <a href="#company" className="nav-link">Company</a>
        </div>
        <div className="nav-cta">
          <a href="#contact" className="btn btn-primary">
            Talk to sales <Icon.Arrow/>
          </a>
        </div>
      </div>
    </nav>
  );
}

// Make available to other files
window.RivalIcons = Icon;
window.RivalWordmark = Wordmark;
window.RivalNav = Nav;
