// Header / nav
const { useState, useEffect, useRef, useMemo } = React;

function Logo({size=46, mark=true}){
  // Double-ring badge with the Ampersand Peach mark — matches the Logo Asset Pack.
  return (
    <a href="#top" style={{display:'flex', alignItems:'center', gap:14}}>
      <span style={{
        width:size, height:size, borderRadius:'50%',
        background:'var(--cream)',
        border:`1.5px solid var(--tomato)`,
        position:'relative',
        flexShrink:0,
        display:'grid', placeItems:'center'
      }}>
        <span style={{
          position:'absolute', inset:'10%', borderRadius:'50%',
          border:'1.2px solid var(--tomato)'
        }}/>
        <svg width={size*0.58} height={size*0.62} viewBox="0 0 60 64" aria-hidden style={{position:'relative'}}>
          {/* stem */}
          <path d="M30 22 C 30 14, 30 10, 30 6" stroke="#1A2418" strokeWidth="1.6" strokeLinecap="round" fill="none"/>
          {/* leaf — single, to the right */}
          <path d="M30 12 C 36 8, 44 8, 46 14 C 42 18, 34 18, 30 12 Z" fill="#1F3D2E"/>
          {/* fruit body — round plum/cherry */}
          <ellipse cx="30" cy="40" rx="18" ry="19" fill="#D63B27"/>
          {/* center dimple */}
          <path d="M30 23 C 28 36, 28 52, 30 58" stroke="#1A2418" strokeOpacity="0.22" strokeWidth="1.4" fill="none"/>
          {/* highlight */}
          <ellipse cx="22" cy="32" rx="3.6" ry="6" fill="#FAF6EC" opacity="0.34" transform="rotate(-22 22 32)"/>
        </svg>
      </span>
      <span style={{display:'flex', flexDirection:'column', lineHeight:1}}>
        <span style={{fontFamily:"'NormalAmp', 'Archivo', 'Arial Black', sans-serif", fontWeight:800, color:'var(--tomato)', fontSize:20, letterSpacing:'-0.02em'}}>P&amp;L England</span>
        <span style={{fontSize:9.5, fontWeight:600, color:'var(--ink-3)', letterSpacing:'0.32em', textTransform:'uppercase', marginTop:5}}>Simply Fresh</span>
      </span>
    </a>
  );
}

function Nav(){
  const [scrolled, setScrolled] = useState(false);
  const [open, setOpen] = useState(false);
  useEffect(()=>{
    const onScroll = ()=> setScrolled(window.scrollY > 40);
    window.addEventListener('scroll', onScroll);
    return ()=> window.removeEventListener('scroll', onScroll);
  },[]);
  const links = [
    ['About','#about'],
    ['What We Do','#services'],
    ['Produce','#produce'],
    ['Routes','#routes'],
    ['Contact','#quote'],
  ];
  return (
    <header style={{
      position:'sticky', top:0, zIndex:50,
      background: scrolled ? 'rgba(246,241,230,0.92)' : 'transparent',
      backdropFilter: scrolled ? 'blur(12px) saturate(140%)' : 'none',
      borderBottom: scrolled ? '1px solid var(--line-soft)' : '1px solid transparent',
      transition:'background 0.25s, border-color 0.25s'
    }}>
      <div className="container" style={{display:'flex', alignItems:'center', justifyContent:'space-between', padding:'18px 0', gap:24}}>
        <Logo/>
        <nav className="nav-links" style={{display:'flex', gap:32, alignItems:'center'}}>
          {links.map(([l,h])=>(
            <a key={h} href={h} style={{fontSize:14.5, fontWeight:500, color:'var(--ink-2)', transition:'color .15s'}}
               onMouseEnter={e=>e.currentTarget.style.color='var(--ink)'}
               onMouseLeave={e=>e.currentTarget.style.color='var(--ink-2)'}>
              {l}
            </a>
          ))}
        </nav>
        <div style={{display:'flex', gap:10, alignItems:'center'}}>
          <a href="http://wa.me/+447808034216" className="btn btn-ghost" style={{padding:'10px 14px', fontSize:13}}>
            <Icon.Whatsapp size={15}/>
            <span className="wa-label">WhatsApp</span>
          </a>
          <a href="#quote" className="btn btn-primary" style={{padding:'12px 18px', fontSize:13.5}}>
            Request a Quote <Icon.Arrow size={14}/>
          </a>
          <button className="menu-btn" onClick={()=>setOpen(!open)} style={{display:'none'}}>
            <Icon.Menu/>
          </button>
        </div>
      </div>
      {open && (
        <div className="mobile-menu" style={{padding:'12px 0 20px', borderTop:'1px solid var(--line-soft)'}}>
          <div className="container" style={{display:'flex', flexDirection:'column', gap:14}}>
            {links.map(([l,h])=>(<a key={h} href={h} onClick={()=>setOpen(false)} style={{fontSize:18, fontFamily:'var(--serif)'}}>{l}</a>))}
          </div>
        </div>
      )}
      <style>{`
        @media (max-width: 900px) {
          .nav-links { display: none !important; }
          .menu-btn { display: flex !important; }
          .wa-label { display: none; }
        }
      `}</style>
    </header>
  );
}

Object.assign(window, { Logo, Nav });
