/* Shared nav + footer + theme toggle. Reads ?theme= from localStorage. */

const NAV_LINKS = [
  { href: 'index.html', label: 'Home', id: 'home' },
  { href: 'tech.html', label: 'Tech', id: 'tech' },
  { href: 'about.html', label: 'About', id: 'about' },
  { href: 'reserve.html', label: 'Back Us', id: 'reserve' },
];

function Nav({ active }) {
  const [theme, setTheme] = React.useState(
    () => localStorage.getItem('zephyr-theme') || 'light'
  );
  const [mobileMenuOpen, setMobileMenuOpen] = React.useState(false);

  React.useEffect(() => {
    document.documentElement.setAttribute('data-theme', theme);
    localStorage.setItem('zephyr-theme', theme);
  }, [theme]);

  return (
    <>
      <nav className="nav">
        <a href="index.html" className="nav-logo">
          <img src="Logo.png" alt="Zephyr" className="logo-mark" />
          <img src="Pink Word.png" alt="ZEPHYR" className="logo-word" />
        </a>

        <div className="nav-links">
          {NAV_LINKS.map(l => (
            <a
              key={l.id}
              href={l.href}
              className={`nav-link ${active === l.id ? 'active' : ''}`}
            >
              {l.label}
            </a>
          ))}
        </div>

        <div className="nav-right">
          <button
            className="theme-toggle"
            onClick={() => setTheme(t => t === 'light' ? 'dark' : 'light')}
            aria-label="Toggle theme"
            title="Toggle theme"
          >
            {theme === 'light' ? '☾' : '☀'}
          </button>
          <button
            className="mobile-menu-btn"
            onClick={() => setMobileMenuOpen(!mobileMenuOpen)}
            aria-label="Toggle menu"
          >
            <span></span>
            <span></span>
            <span></span>
          </button>
          <a href="https://www.gofundme.com/f/bring-zephyr-longboards-to-life" target="_blank" rel="noopener noreferrer" className="nav-cta">Back Us →</a>
        </div>
      </nav>

      {mobileMenuOpen && (
        <div className="mobile-menu">
          {NAV_LINKS.map(l => (
            <a
              key={l.id}
              href={l.href}
              className={`mobile-menu-link ${active === l.id ? 'active' : ''}`}
              onClick={() => setMobileMenuOpen(false)}
            >
              {l.label}
            </a>
          ))}
        </div>
      )}
    </>
  );
}

function ZephyrMark() {
  return (
    <svg width="28" height="28" viewBox="0 0 28 28" fill="none">
      <path d="M4 8 L24 8 L8 20 L24 20" stroke="currentColor" strokeWidth="2.5" strokeLinecap="square" fill="none"/>
      <circle cx="22" cy="6" r="3" fill="#ff2d87"/>
    </svg>
  );
}

function SocialIcon({ href, label, brandColor, children }) {
  return (
    <a
      href={href}
      target="_blank"
      rel="noopener noreferrer"
      aria-label={label}
      style={{
        width: 44,
        height: 44,
        borderRadius: '50%',
        border: '2px solid var(--line)',
        display: 'grid',
        placeItems: 'center',
        color: 'var(--fg)',
        transition: 'all 0.25s cubic-bezier(0.4, 0, 0.2, 1)',
        background: 'var(--card)',
      }}
      onMouseEnter={(e) => {
        e.currentTarget.style.background = brandColor;
        e.currentTarget.style.borderColor = brandColor;
        e.currentTarget.style.color = '#fff';
        e.currentTarget.style.transform = 'translateY(-4px) scale(1.05)';
        e.currentTarget.style.boxShadow = `0 8px 16px ${brandColor}40`;
      }}
      onMouseLeave={(e) => {
        e.currentTarget.style.background = 'var(--card)';
        e.currentTarget.style.borderColor = 'var(--line)';
        e.currentTarget.style.color = 'var(--fg)';
        e.currentTarget.style.transform = 'translateY(0) scale(1)';
        e.currentTarget.style.boxShadow = 'none';
      }}
    >
      {children}
    </a>
  );
}

function Footer() {
  return (
    <footer className="footer">
      <div className="footer-inner">
        <div style={{ display: 'flex', flexDirection: 'column', alignItems: 'center', justifyContent: 'center', gap: '12px' }}>
          <img src="Pink Word.png" alt="ZEPHYR" className="footer-logo" />
          <p className="mono" style={{ fontSize: 14, margin: 0, color: 'var(--fg-muted)', letterSpacing: '0.1em', textTransform: 'uppercase', fontWeight: 600 }}>
            CARRY THE RIDE.
          </p>
        </div>
        <div className="footer-col">
          <h4>Product</h4>
          <ul>
            <li><a href="tech.html">Technology</a></li>
            <li><a href="tech.html#specs">Specs</a></li>
            <li><a href="reserve.html">Reserve</a></li>
          </ul>
        </div>
        <div className="footer-col">
          <h4>Company</h4>
          <ul>
            <li><a href="about.html">About</a></li>
            <li><a href="about.html#team">Team</a></li>
            <li><a href="mailto:zephyrboards@gmail.com">Contact</a></li>
          </ul>
        </div>
        <div className="footer-col">
          <h4>Follow</h4>
          <div style={{ display: 'flex', gap: 14, marginTop: 16, flexWrap: 'wrap' }}>
            <SocialIcon href="https://www.instagram.com/zephyrboards/" label="Instagram" brandColor="#E4405F">
              <svg width="26" height="26" fill="currentColor" viewBox="0 0 24 24">
                <path d="M12 2.163c3.204 0 3.584.012 4.85.07 3.252.148 4.771 1.691 4.919 4.919.058 1.265.069 1.645.069 4.849 0 3.205-.012 3.584-.069 4.849-.149 3.225-1.664 4.771-4.919 4.919-1.266.058-1.644.07-4.85.07-3.204 0-3.584-.012-4.849-.07-3.26-.149-4.771-1.699-4.919-4.92-.058-1.265-.07-1.644-.07-4.849 0-3.204.013-3.583.07-4.849.149-3.227 1.664-4.771 4.919-4.919 1.266-.057 1.645-.069 4.849-.069zm0-2.163c-3.259 0-3.667.014-4.947.072-4.358.2-6.78 2.618-6.98 6.98-.059 1.281-.073 1.689-.073 4.948 0 3.259.014 3.668.072 4.948.2 4.358 2.618 6.78 6.98 6.98 1.281.058 1.689.072 4.948.072 3.259 0 3.668-.014 4.948-.072 4.354-.2 6.782-2.618 6.979-6.98.059-1.28.073-1.689.073-4.948 0-3.259-.014-3.667-.072-4.947-.196-4.354-2.617-6.78-6.979-6.98-1.281-.059-1.69-.073-4.949-.073zm0 5.838c-3.403 0-6.162 2.759-6.162 6.162s2.759 6.163 6.162 6.163 6.162-2.759 6.162-6.163c0-3.403-2.759-6.162-6.162-6.162zm0 10.162c-2.209 0-4-1.79-4-4 0-2.209 1.791-4 4-4s4 1.791 4 4c0 2.21-1.791 4-4 4zm6.406-11.845c-.796 0-1.441.645-1.441 1.44s.645 1.44 1.441 1.44c.795 0 1.439-.645 1.439-1.44s-.644-1.44-1.439-1.44z"/>
              </svg>
            </SocialIcon>
            <SocialIcon href="https://www.tiktok.com/@zephyrboards" label="TikTok" brandColor="#000000">
              <svg width="26" height="26" fill="currentColor" viewBox="0 0 24 24">
                <path d="M19.59 6.69a4.83 4.83 0 0 1-3.77-4.25V2h-3.45v13.67a2.89 2.89 0 0 1-5.2 1.74 2.89 2.89 0 0 1 2.31-4.64 2.93 2.93 0 0 1 .88.13V9.4a6.84 6.84 0 0 0-1-.05A6.33 6.33 0 0 0 5 20.1a6.34 6.34 0 0 0 10.86-4.43v-7a8.16 8.16 0 0 0 4.77 1.52v-3.4a4.85 4.85 0 0 1-1-.1z"/>
              </svg>
            </SocialIcon>
            <SocialIcon href="https://www.linkedin.com/company/zephyr-boards/" label="LinkedIn" brandColor="#0A66C2">
              <svg width="26" height="26" fill="currentColor" viewBox="0 0 24 24">
                <path d="M20.447 20.452h-3.554v-5.569c0-1.328-.027-3.037-1.852-3.037-1.853 0-2.136 1.445-2.136 2.939v5.667H9.351V9h3.414v1.561h.046c.477-.9 1.637-1.85 3.37-1.85 3.601 0 4.267 2.37 4.267 5.455v6.286zM5.337 7.433c-1.144 0-2.063-.926-2.063-2.065 0-1.138.92-2.063 2.063-2.063 1.14 0 2.064.925 2.064 2.063 0 1.139-.925 2.065-2.064 2.065zm1.782 13.019H3.555V9h3.564v11.452zM22.225 0H1.771C.792 0 0 .774 0 1.729v20.542C0 23.227.792 24 1.771 24h20.451C23.2 24 24 23.227 24 22.271V1.729C24 .774 23.2 0 22.222 0h.003z"/>
              </svg>
            </SocialIcon>
            <SocialIcon href="https://www.facebook.com/profile.php?id=61589139005330" label="Facebook" brandColor="#1877F2">
              <svg width="26" height="26" fill="currentColor" viewBox="0 0 24 24">
                <path d="M24 12.073c0-6.627-5.373-12-12-12s-12 5.373-12 12c0 5.99 4.388 10.954 10.125 11.854v-8.385H7.078v-3.47h3.047V9.43c0-3.007 1.792-4.669 4.533-4.669 1.312 0 2.686.235 2.686.235v2.953H15.83c-1.491 0-1.956.925-1.956 1.874v2.25h3.328l-.532 3.47h-2.796v8.385C19.612 23.027 24 18.062 24 12.073z"/>
              </svg>
            </SocialIcon>
            <SocialIcon href="https://www.gofundme.com/f/bring-zephyr-longboards-to-life" label="GoFundMe" brandColor="#00B964">
              <svg width="26" height="26" fill="currentColor" viewBox="0 0 24 24">
                <path d="M12.874 14.812c0 1.674-1.355 3.029-3.028 3.029s-3.029-1.355-3.029-3.029c0-1.673 1.356-3.028 3.029-3.028s3.028 1.355 3.028 3.028zm4.615-7.973c-2.135 0-3.949 1.404-4.577 3.341h-.048c-.63-1.937-2.443-3.341-4.579-3.341-2.664 0-4.822 2.159-4.822 4.823 0 2.665 2.158 4.824 4.822 4.824 2.136 0 3.95-1.405 4.579-3.342h.048c.628 1.937 2.442 3.342 4.577 3.342 2.665 0 4.823-2.159 4.823-4.824 0-2.664-2.158-4.823-4.823-4.823zM17.489 15.5c-1.674 0-3.029-1.355-3.029-3.028 0-1.674 1.355-3.028 3.029-3.028 1.673 0 3.028 1.354 3.028 3.028 0 1.673-1.355 3.028-3.028 3.028z"/>
              </svg>
            </SocialIcon>
          </div>
        </div>
      </div>
      <div className="footer-bottom">
        <span>© 2026 Zephyr Boards · Champaign, IL</span>
        <span>Patent pending</span>
      </div>
    </footer>
  );
}

window.Nav = Nav;
window.Footer = Footer;
