// Shared core components — Logo, Icon, Nav, Footer

const Logo = ({h = 22, inverse = false, className = "", style = {}}) => (
  <span className={`lq-logo ${inverse ? "inverse" : ""} ${className}`} style={{"--lq-h": h + "px", ...style}}>
    <span className="lq-stairs" aria-hidden="true">
      <span className="b1"></span><span className="b2"></span><span className="b3"></span>
    </span>
    <span className="lq-word">LEAP<span className="accent">STAQ</span></span>
  </span>
);

const Mark = ({h = 22, inverse = false, style = {}}) => (
  <span className={`lq-logo ${inverse ? "inverse" : ""}`} style={{"--lq-h": h + "px", gap: 0, ...style}}>
    <span className="lq-stairs" aria-hidden="true">
      <span className="b1"></span><span className="b2"></span><span className="b3"></span>
    </span>
  </span>
);

const Icon = ({name, size = 20, className = "", style = {}}) => {
  const paths = {
    "arrow-right":    <><path d="M5 12h14"/><path d="M12 5l7 7-7 7"/></>,
    "arrow-up-right": <><path d="M7 17L17 7"/><path d="M7 7h10v10"/></>,
    "arrow-down-right": <><path d="M7 7l10 10"/><path d="M17 7v10h-10"/></>,
    "check":          <polyline points="20 6 9 17 4 12"/>,
    "zap":            <path d="M13 2L3 14h9l-1 8 10-12h-9l1-8z"/>,
    "database":       <><ellipse cx="12" cy="5" rx="9" ry="3"/><path d="M3 5v14c0 1.66 4.03 3 9 3s9-1.34 9-3V5"/><path d="M3 12c0 1.66 4.03 3 9 3s9-1.34 9-3"/></>,
    "code":           <><polyline points="8 6 2 12 8 18"/><polyline points="16 6 22 12 16 18"/></>,
    "package":        <path d="M21 16V8a2 2 0 00-1-1.73l-7-4a2 2 0 00-2 0l-7 4A2 2 0 003 8v8a2 2 0 001 1.73l7 4a2 2 0 002 0l7-4A2 2 0 0021 16z"/>,
    "activity":       <polyline points="22 12 18 12 15 21 9 3 6 12 2 12"/>,
    "menu":           <><line x1="3" y1="6" x2="21" y2="6"/><line x1="3" y1="12" x2="21" y2="12"/><line x1="3" y1="18" x2="21" y2="18"/></>,
    "users":          <><path d="M17 21v-2a4 4 0 00-4-4H5a4 4 0 00-4 4v2"/><circle cx="9" cy="7" r="4"/><path d="M23 21v-2a4 4 0 00-3-3.87"/><path d="M16 3.13a4 4 0 010 7.75"/></>,
    "layers":         <><polygon points="12 2 2 7 12 12 22 7 12 2"/><polyline points="2 17 12 22 22 17"/><polyline points="2 12 12 17 22 12"/></>,
    "git-branch":     <><line x1="6" y1="3" x2="6" y2="15"/><circle cx="18" cy="6" r="3"/><circle cx="6" cy="18" r="3"/><path d="M18 9a9 9 0 01-9 9"/></>,
    "aperture":       <><circle cx="12" cy="12" r="10"/><path d="M14.31 8l5.74 9.94"/><path d="M9.69 8h11.48"/><path d="M7.38 12l5.74-9.94"/><path d="M9.69 16L3.95 6.06"/><path d="M14.31 16H2.83"/><path d="M16.62 12l-5.74 9.94"/></>,
    "terminal":       <><polyline points="4 17 10 11 4 5"/><line x1="12" y1="19" x2="20" y2="19"/></>,
    "map-pin":        <><path d="M21 10c0 7-9 13-9 13s-9-6-9-13a9 9 0 0118 0z"/><circle cx="12" cy="10" r="3"/></>,
    "external":       <><path d="M18 13v6a2 2 0 01-2 2H5a2 2 0 01-2-2V8a2 2 0 012-2h6"/><polyline points="15 3 21 3 21 9"/><line x1="10" y1="14" x2="21" y2="3"/></>,
    "plus":           <><line x1="12" y1="5" x2="12" y2="19"/><line x1="5" y1="12" x2="19" y2="12"/></>,
    "dot":            <circle cx="12" cy="12" r="4"/>,
  };
  return (
    <svg className={className} style={style} width={size} height={size} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.75" strokeLinecap="round" strokeLinejoin="round">
      {paths[name] || null}
    </svg>
  );
};

const Eyebrow = ({children, className = "", style = {}}) => (
  <span className={`lq-eyebrow ${className}`} style={style}>{children}</span>
);

const Nav = ({theme = "light"}) => {
  const dark = theme === "dark";
  const items = [
    { k: "services", href: "#services", label: "the services" },
    { k: "products", href: "#products", label: "the products" },
    { k: "network",  href: "#network",  label: "the network" },
    { k: "team",     href: "#team",     label: "the team" },
    { k: "careers",  href: "#careers",  label: "careers" },
  ];
  return (
    <nav className={`lq-nav ${dark ? "lq-nav-dark" : ""}`}>
      <a href="#top" className="lq-nav-logo">
        <Logo h={22} inverse={dark}/>
      </a>
      <div className="lq-nav-links">
        {items.map(i => (
          <a key={i.k} href={i.href} onClick={(e)=>{
            e.preventDefault();
            const el = document.querySelector(i.href);
            if (el) window.scrollTo({top: el.offsetTop - 64, behavior:"smooth"});
          }}>{i.label}</a>
        ))}
      </div>
      <div className="lq-nav-cta">
        <a href="#contact" className="lq-btn lq-btn-ghost" onClick={(e)=>{e.preventDefault();const el=document.querySelector("#contact");el&&window.scrollTo({top:el.offsetTop-64,behavior:"smooth"})}}>Let's talk</a>
        <a href="#contact" className="lq-btn lq-btn-primary" onClick={(e)=>{e.preventDefault();const el=document.querySelector("#contact");el&&window.scrollTo({top:el.offsetTop-64,behavior:"smooth"})}}>
          Start a project <Icon name="arrow-right" size={16}/>
        </a>
      </div>
    </nav>
  );
};

const Footer = () => (
  <footer className="lq-footer" id="contact-footer">
    <div className="lq-container">
      <div className="lq-footer-cols" style={{display:"grid",gridTemplateColumns:"1.6fr repeat(4,1fr)",gap:40,marginBottom:56}}>
        <div>
          <div style={{marginBottom:20}}><Logo h={24} inverse/></div>
          <p style={{fontFamily:"var(--font-body)",fontSize:14,lineHeight:1.55,color:"var(--navy-200)",margin:"0 0 20px",maxWidth:"38ch"}}>
            One network, integrated solutions. Lasting impact — Hoofddorp · Warsaw · Paramaribo · Cimaja.
          </p>
          <div style={{fontFamily:"var(--font-mono)",fontSize:12,color:"var(--navy-300)",lineHeight:1.8}}>
            <div>Bijlmermeerstraat 18A</div>
            <div>2131HG Hoofddorp · NL</div>
            <div style={{marginTop:10}}><a href="mailto:info@leapstaq.com" style={{color:"var(--signal-400)"}}>info@leapstaq.com</a></div>
            <div style={{marginTop:6}}><a href="https://github.com/Devleaps" target="_blank" rel="noopener noreferrer" style={{color:"var(--signal-400)",display:"inline-flex",alignItems:"center",gap:6}}><Icon name="git-branch" size={14}/>github.com/Devleaps</a></div>
          </div>
        </div>
        <div><h4>services</h4><ul><li><a href="#services">Cloud & platform</a></li><li><a href="#services">DevEx</a></li><li><a href="#services">Data</a></li><li><a href="#services">AI</a></li><li><a href="#services">Transformations</a></li></ul></div>
        <div><h4>company</h4><ul><li><a href="#about">Who we are</a></li><li><a href="#network">The network</a></li><li><a href="#team">The team</a></li><li><a href="#careers">Join the club</a></li></ul></div>
        <div><h4>work</h4><ul><li><a href="#products">Products</a></li><li><a href="#clients">Clients</a></li><li><a href="#tech">Tech we love</a></li><li><a href="https://github.com/Devleaps" target="_blank" rel="noopener noreferrer">Open source</a></li></ul></div>
        <div><h4>connect</h4><ul><li><a href="#contact">Let's talk</a></li><li><a href="#">LinkedIn</a></li><li><a href="https://github.com/Devleaps" target="_blank" rel="noopener noreferrer">GitHub</a></li></ul></div>
      </div>
      <div style={{display:"flex",justifyContent:"space-between",alignItems:"center",paddingTop:28,borderTop:"1px solid rgba(159,180,219,.12)",fontFamily:"var(--font-mono)",fontSize:12,color:"var(--navy-300)"}}>
        <span><span style={{opacity:.6}}>// </span>leapstaq / hoofddorp · {new Date().getFullYear()}</span>
        <span>v1.0.0 · <a href="#" style={{color:"var(--navy-300)"}}>privacy</a> · <a href="#" style={{color:"var(--navy-300)"}}>terms</a></span>
      </div>
    </div>
  </footer>
);

const ClientMark = ({name, inverse = false}) => (
  <span style={{
    fontFamily: "var(--font-display)",
    fontWeight: 700,
    fontSize: 20,
    letterSpacing: "-0.03em",
    color: inverse ? "rgba(255,255,255,.68)" : "var(--ink-500)",
    whiteSpace: "nowrap"
  }}>{name}</span>
);

const TeamAvatar = ({name, photo, size = 56}) => {
  const { bg, initial } = avatarFor(name);
  const [err, setErr] = React.useState(false);
  if (photo && !err) {
    return (
      <img src={photo} alt={name} onError={()=>setErr(true)} style={{
        width: size, height: size, borderRadius: 999, objectFit: "cover",
        background: bg, flexShrink: 0,
        boxShadow: "inset 0 0 0 1px rgba(255,255,255,.06)"
      }}/>
    );
  }
  return (
    <div style={{
      width: size, height: size, borderRadius: 999, background: bg, color: "#fff",
      display: "flex", alignItems: "center", justifyContent: "center",
      fontFamily: "var(--font-display)", fontWeight: 600, fontSize: size * 0.42,
      letterSpacing: "-0.02em", flexShrink: 0,
      boxShadow: "inset 0 0 0 1px rgba(255,255,255,.06)"
    }}>{initial}</div>
  );
};

Object.assign(window, { Logo, Mark, Icon, Eyebrow, Nav, Footer, ClientMark, TeamAvatar });
