// Nav.jsx — Delvecore Website UI Kit (responsive)
function LogoMark({ size = 22, color = '#0C0C0A' }) {
  return (
    <svg width={size} height={size} viewBox="0 0 64 64" fill="none" style={{ flexShrink: 0 }}>
      <circle cx="32" cy="32" r="28" fill="none" stroke={color} strokeWidth="3"/>
      <circle cx="32" cy="32" r="20" fill="none" stroke={color} strokeWidth="1.5" opacity="0.45"/>
      <path d="M 32 17 Q 41 24 41 32 Q 41 40 32 47" fill="none" stroke={color} strokeWidth="2.5" strokeLinecap="round"/>
    </svg>
  );
}

window.Nav = function Nav({ scrolled = false }) {
  const mobile = useIsMobile();
  const [menuOpen, setMenuOpen] = React.useState(false);

  return (
    <>
      <nav style={{
        position: 'fixed', top: 0, left: 0, right: 0, zIndex: 100,
        padding: mobile ? '20px 24px' : '28px 48px',
        display: 'flex', alignItems: 'center', justifyContent: 'space-between',
        background: (scrolled || menuOpen) ? 'rgba(248,247,245,0.96)' : 'transparent',
        backdropFilter: (scrolled || menuOpen) ? 'blur(12px)' : 'none',
        borderBottom: (scrolled || menuOpen) ? '1px solid #E0DFD8' : 'none',
        transition: 'background 0.4s ease, border-bottom 0.4s ease',
      }}>
        <a href="#hero" style={{ display: 'flex', alignItems: 'center', gap: 10, textDecoration: 'none', color: '#0C0C0A' }}>
          <LogoMark />
          <span style={{ fontFamily: "'Cormorant Garamond', Georgia, serif", fontSize: 20, fontWeight: 400, letterSpacing: '0.08em' }}>
            Delvecore
          </span>
        </a>

        {/* Desktop links */}
        {!mobile && (
          <ul style={{ display: 'flex', gap: 36, listStyle: 'none', margin: 0, padding: 0 }}>
            {['Services', 'Works', 'Pricing', 'Flow', 'FAQ', 'About', 'Contact'].map(item => (
              <li key={item}><NavLink href={`#${item.toLowerCase()}`} label={item} /></li>
            ))}
          </ul>
        )}

        {/* Hamburger */}
        {mobile && (
          <button onClick={() => setMenuOpen(o => !o)} style={{ background: 'none', border: 'none', cursor: 'pointer', padding: 4, display: 'flex', flexDirection: 'column', gap: 5 }}>
            {[0,1,2].map(i => (
              <span key={i} style={{ display: 'block', width: 22, height: 1, background: '#0C0C0A', transition: 'transform 0.3s, opacity 0.3s',
                transform: menuOpen && i === 0 ? 'translateY(6px) rotate(45deg)' : menuOpen && i === 2 ? 'translateY(-6px) rotate(-45deg)' : 'none',
                opacity: menuOpen && i === 1 ? 0 : 1,
              }} />
            ))}
          </button>
        )}
      </nav>

      {/* Mobile drawer */}
      {mobile && (
        <div style={{
          position: 'fixed', top: 61, left: 0, right: 0, zIndex: 99,
          background: 'rgba(248,247,245,0.98)', backdropFilter: 'blur(12px)',
          borderBottom: '1px solid #E0DFD8',
          maxHeight: menuOpen ? 300 : 0, overflow: 'hidden',
          transition: 'max-height 0.4s cubic-bezier(0.4,0,0.2,1)',
        }}>
          <ul style={{ listStyle: 'none', padding: '16px 24px 24px' }}>
            {['Services', 'Works', 'Pricing', 'Flow', 'FAQ', 'About', 'Contact'].map(item => (
              <li key={item} style={{ borderBottom: '1px solid #E0DFD8', padding: '14px 0' }}>
                <a href={`#${item.toLowerCase()}`} onClick={() => setMenuOpen(false)}
                  style={{ fontSize: 13, letterSpacing: '0.12em', textTransform: 'uppercase', textDecoration: 'none', color: '#0C0C0A' }}>
                  {item}
                </a>
              </li>
            ))}
          </ul>
        </div>
      )}
    </>
  );
};

function NavLink({ href, label }) {
  const [hovered, setHovered] = React.useState(false);
  return (
    <a href={href}
      onMouseEnter={() => setHovered(true)}
      onMouseLeave={() => setHovered(false)}
      style={{ fontSize: 12, letterSpacing: '0.12em', textTransform: 'uppercase', textDecoration: 'none', color: hovered ? '#0C0C0A' : '#888884', transition: 'color 0.2s', position: 'relative', paddingBottom: 4 }}>
      {label}
      <span style={{ position: 'absolute', bottom: -2, left: 0, width: hovered ? '100%' : 0, height: 1, background: '#0C0C0A', transition: 'width 0.3s ease' }} />
    </a>
  );
}
