function LinkCard({ label, href, onClick, external }) {
  const [hover, setHover] = React.useState(false);
  const handleClick = (e) => {
    if (onClick) { e.preventDefault(); onClick(); }
  };
  return (
    <a href={href} onClick={handleClick}
       target={external ? '_blank' : undefined}
       rel={external ? 'noopener noreferrer' : undefined}
       onMouseEnter={()=>setHover(true)} onMouseLeave={()=>setHover(false)}
       style={{ display:'flex', alignItems:'center', justifyContent:'space-between', padding:'28px 0',
                borderTop:`1px solid ${hover ? 'rgba(247,63,52,0.45)' : 'rgba(249,250,251,0.10)'}`,
                font:'400 16px/1 var(--rz-font-mono)',
                color: hover ? '#f73f34' : '#F9FAFB', textDecoration:'none',
                paddingLeft: hover ? 8 : 0,
                transition:'color 280ms cubic-bezier(.22,1,.36,1), border-color 280ms ease, padding-left 320ms cubic-bezier(.22,1,.36,1)' }}>
      <span>{label}</span>
      <span style={{ display:'inline-block',
                     transform: hover ? 'translateX(6px)' : 'translateX(0)',
                     color: hover ? '#f73f34' : '#F9FAFB',
                     transition:'transform 240ms cubic-bezier(.22,1,.36,1), color 240ms ease' }}>
        {external ? '↗' : '→'}
      </span>
    </a>
  );
}

function Footer() {
  const [contactOpen, setContactOpen] = React.useState(false);
  const goHash = (hash) => () => {
    if (window.location.pathname === '/' || window.location.pathname.endsWith('index.html')) {
      const el = document.querySelector(hash);
      if (el) el.scrollIntoView({ behavior:'smooth', block:'start' });
    } else {
      window.location.href = '/' + hash;
    }
  };
  const goHome = () => {
    if (window.location.pathname === '/' || window.location.pathname.endsWith('index.html')) {
      window.scrollTo({ top:0, behavior:'smooth' });
    } else {
      window.location.href = '/';
    }
  };
  return (
    <>
      <footer style={{ background:'#25282C', color:'#F9FAFB', padding:'80px 56px 40px' }}>
        <div className="rz-footer-grid" style={{ display:'grid', gridTemplateColumns:'1.2fr 1fr 1fr', gap:64 }}>
          <div>
            <div style={{ display:'flex', alignItems:'center', gap:12 }}>
              <img src="assets/logo/Rayzor Logo icon new.png" alt="Rayzor icon"
                   style={{ height:32, filter:'invert(1)' }}/>
              <img src="assets/logo/New Rayzor Logo Text.png" alt="Rayzor"
                   style={{ height:26, filter:'invert(1)' }}/>
            </div>
            <div style={{ height:32 }}/>
            <div style={{ font:'400 14px/1.7 var(--rz-font-mono)', color:'#9aa0a6' }}>
              Empowering the future.<br/>
              hello@rayzorice.com<br/>
              © 2026 Rayzor Robotics
            </div>
          </div>
          <div>
            <LinkCard label="Rayzor V1" href="#top" onClick={goHome}/>
            <LinkCard label="Mission" href="#mission" onClick={goHash('#mission')}/>
            <LinkCard label="Traction" href="#traction" onClick={goHash('#traction')}/>
          </div>
          <div>
            <LinkCard label="Press" href="https://www.linkedin.com/company/rayzor-ice-resurfacing/" external/>
            <LinkCard label="Investors" href="/investors.html"/>
            <LinkCard label="Contact" href="#contact" onClick={()=>setContactOpen(true)}/>
          </div>
        </div>
      </footer>
      <ContactModal open={contactOpen} onClose={()=>setContactOpen(false)}/>
    </>
  );
}
window.Footer = Footer;
window.LinkCard = LinkCard;
