// Shared chrome for the NeoHelio website: top nav, footer, eyebrow,
// CTA blocks, striped image placeholders. Imported by every page.

// ────────── Top nav ──────────
// Active page is passed in. Status pip on the right uses the same fleet
// nominal cue the operator console uses, tying the marketing site to the
// product chrome.
const SiteNav = ({ active = "home" }) => {
  const [scrolled, setScrolled] = React.useState(false);
  React.useEffect(() => {
    const onScroll = () => setScrolled(window.scrollY > 20);
    onScroll();
    window.addEventListener("scroll", onScroll, { passive: true });
    return () => window.removeEventListener("scroll", onScroll);
  }, []);

  const links = [
    ["home", "Home", "index.html"],
    ["product", "Product", "product.html"],
    ["company", "Company", "company.html"],
    ["contact", "Contact", "contact.html"],
  ];

  return (
    <nav style={{
      position: "sticky", top: 0, zIndex: 50,
      height: 72,
      display: "flex", alignItems: "center", justifyContent: "space-between",
      padding: "0 56px",
      borderBottom: `1px solid ${scrolled ? "var(--nh-line)" : "transparent"}`,
      background: scrolled ? "rgba(10,14,26,0.78)" : "transparent",
      backdropFilter: scrolled ? "blur(14px)" : "none",
      WebkitBackdropFilter: scrolled ? "blur(14px)" : "none",
      transition: "background .25s ease, border-color .25s ease",
    }}>
      <a href="index.html" style={{ display: "flex", alignItems: "baseline", gap: 14 }}>
        <span style={{
          fontFamily: "var(--nh-display)", fontWeight: 600, fontSize: 22,
          letterSpacing: "-0.035em", color: "var(--nh-ink)",
        }}>
          neohelio<span className="nh-period-glow" style={{ color: "var(--nh-accent)" }}>.</span>
        </span>
      </a>
      <div style={{ display: "flex", gap: 36 }}>
        {links.map(([k, label, href]) => (
          <a key={k} href={href} style={{
            position: "relative",
            fontFamily: "var(--nh-sans)", fontSize: 14, fontWeight: 500,
            color: active === k ? "var(--nh-ink)" : "var(--nh-ink-3)",
            padding: "26px 0",
            transition: "color .15s ease",
          }}
            onMouseEnter={(e) => { if (active !== k) e.currentTarget.style.color = "var(--nh-ink)"; }}
            onMouseLeave={(e) => { if (active !== k) e.currentTarget.style.color = "var(--nh-ink-3)"; }}>
            {label}
            {active === k && (
              <span style={{
                position: "absolute", bottom: -1, left: 0, right: 0,
                height: 2, background: "var(--nh-accent)",
              }} />
            )}
          </a>
        ))}
      </div>
      <div style={{ display: "flex", gap: 14, alignItems: "center" }}>
        <a href="contact.html" className="site-btn site-btn--primary"
           style={{ padding: "10px 18px", fontSize: 11 }}>
          Request access
        </a>
      </div>
    </nav>
  );
};

// ────────── Footer ──────────
const SiteFooter = () => (
  <footer style={{
    borderTop: "1px solid var(--nh-line)",
    padding: "72px 80px 40px",
    background: "var(--nh-bg-2)",
    position: "relative",
  }}>
    <div className="site-wrap">
      <div style={{
        display: "grid", gridTemplateColumns: "1.4fr 1fr 1fr 1fr", gap: 56,
        paddingBottom: 56, borderBottom: "1px solid var(--nh-line)",
      }}>
        <div>
          <div style={{
            fontFamily: "var(--nh-display)", fontWeight: 600, fontSize: 28,
            letterSpacing: "-0.035em", color: "var(--nh-ink)",
          }}>
            neohelio<span style={{ color: "var(--nh-accent)" }}>.</span>
          </div>
          <p style={{
            fontFamily: "var(--nh-sans)", fontSize: 14, lineHeight: 1.6,
            color: "var(--nh-ink-3)", margin: "16px 0 0", maxWidth: 320,
          }}>
            Smart energy management solutions for EPCs.
          </p>
          <div className="nh-mono" style={{
            fontSize: 10, color: "var(--nh-ink-4)", letterSpacing: "0.2em",
            marginTop: 24, textTransform: "uppercase",
          }}>
            ◇ NEOHELIO (PTY) LTD
          </div>
        </div>

        <FooterColumn title="Platform" links={[
          ["orbit · operator console", "product.html#orbit"],
          ["orbit satellite · site integration", "product.html#satellite"],
          ["Capabilities", "product.html#capabilities"],
        ]} />
        <FooterColumn title="Company" links={[
          ["About", "company.html#about"],
          ["Team", "company.html#team"],
          ["Press kit", "#"],
          ["Careers", "#"],
        ]} />
        <FooterColumn title="Contact" links={[
          ["info@neohelio.io", "mailto:info@neohelio.io"],
          ["sales@neohelio.co", "mailto:sales@neohelio.co"],
          ["support@neohelio.co", "mailto:support@neohelio.co"],
          ["LinkedIn", "#"],
        ]} />
      </div>

      <div style={{
        paddingTop: 32,
        display: "flex", justifyContent: "space-between", alignItems: "flex-end",
        gap: 32, flexWrap: "wrap",
      }}>
        <div className="nh-mono" style={{
          fontSize: 10, color: "var(--nh-ink-4)", letterSpacing: "0.2em",
          textTransform: "uppercase",
        }}>
          © NEOHELIO (PTY) LTD · ALL RIGHTS RESERVED ·{" "}
          <a href="#" style={{ color: "var(--nh-ink-3)" }}>PRIVACY</a> ·{" "}
          <a href="#" style={{ color: "var(--nh-ink-3)" }}>TERMS</a> ·{" "}
          <a href="#" style={{ color: "var(--nh-ink-3)" }}>SOC-2</a>
        </div>

        {/* tick rule — visual sign-off */}
        <div style={{ display: "flex", gap: 4 }}>
          {Array.from({ length: 40 }).map((_, i) => (
            <div key={i} style={{
              width: 2, height: i % 5 === 0 ? 14 : 8,
              background: i % 5 === 0 ? "var(--nh-accent)" : "var(--nh-ink-5)",
            }} />
          ))}
        </div>
      </div>
    </div>
  </footer>
);

const FooterColumn = ({ title, links }) => (
  <div>
    <div className="nh-mono" style={{
      fontSize: 10, color: "var(--nh-ink-4)", letterSpacing: "0.22em",
      textTransform: "uppercase", marginBottom: 18,
    }}>
      ◇ {title}
    </div>
    <ul style={{ listStyle: "none", padding: 0, margin: 0, display: "flex", flexDirection: "column", gap: 10 }}>
      {links.map(([label, href], i) => (
        <li key={i}>
          <a href={href} style={{
            fontFamily: "var(--nh-sans)", fontSize: 14, color: "var(--nh-ink-2)",
            transition: "color .12s ease",
          }}
            onMouseEnter={(e) => e.currentTarget.style.color = "var(--nh-accent)"}
            onMouseLeave={(e) => e.currentTarget.style.color = "var(--nh-ink-2)"}>
            {label}
          </a>
        </li>
      ))}
    </ul>
  </div>
);

// ────────── Reusable section eyebrow ──────────
const SiteEyebrow = ({ id, children }) => (
  <div className="site-eyebrow">
    <span className="rule" />
    <span>◇ {id}</span>
    {children && <>
      <span style={{ color: "var(--nh-ink-4)" }}>·</span>
      <span style={{ color: "var(--nh-ink-3)" }}>{children}</span>
    </>}
  </div>
);

// ────────── Stat readout ──────────
const SiteStat = ({ k, v, unit, tone = "ink" }) => (
  <div>
    <div className="nh-mono" style={{
      fontSize: 10, color: "var(--nh-ink-4)", letterSpacing: "0.18em", textTransform: "uppercase",
    }}>{k}</div>
    <div style={{ display: "flex", alignItems: "baseline", gap: 6, marginTop: 8 }}>
      <span className="nh-mono" style={{
        fontSize: 30, fontWeight: 500, lineHeight: 1,
        color: tone === "amber" ? "var(--nh-accent)" :
               tone === "mint" ? "var(--nh-mint)" :
               "var(--nh-ink)",
      }}>{v}</span>
      {unit && <span className="nh-mono" style={{ fontSize: 11, color: "var(--nh-ink-3)" }}>{unit}</span>}
    </div>
  </div>
);

// ────────── Striped placeholder (for non-user images) ──────────
const SitePlaceholder = ({ label, style }) => (
  <div className="site-placeholder" style={style}>
    <span className="site-placeholder__label">{label}</span>
  </div>
);

// ────────── Image-slot wrapper — for the user to drag real photos onto ──────────
// The starter component is a custom element <image-slot>. We use it inside
// React via React.createElement and pass attrs through. Use distinct ids so
// each slot persists its own dropped image across reloads.
const SiteImageSlot = ({ id, placeholder, style, shape = "rect", radius }) => (
  React.createElement("image-slot", {
    id, placeholder, shape,
    ...(radius ? { radius } : {}),
    style: {
      display: "block",
      width: "100%", height: "100%",
      ...style,
    },
  })
);

// ────────── Big closing CTA strip — reused on Home and Product pages ──────────
const SiteCTA = ({ eyebrow = "NH-CTA/01", title, body, primary = "Request access", primaryHref = "contact.html", secondary, secondaryHref = "#" }) => (
  <section className="site-section" style={{ position: "relative", overflow: "hidden" }}>
    <div className="site-grid" />
    <div className="nh-glow" style={{
      width: 900, height: 900, left: "50%", top: "50%",
      transform: "translate(-50%, -50%)",
      background: "radial-gradient(circle, var(--nh-amber) 0%, transparent 55%)",
      opacity: 0.10,
    }} />
    <div className="site-wrap" style={{
      position: "relative", textAlign: "center",
      display: "flex", flexDirection: "column", alignItems: "center",
    }}>
      <SiteEyebrow id={eyebrow} />
      <h2 className="site-h2" style={{ fontSize: 72, maxWidth: 880 }}>{title}</h2>
      {body && (
        <p className="site-lede" style={{ maxWidth: 580, textAlign: "center" }}>{body}</p>
      )}
      <div style={{ display: "flex", gap: 12, marginTop: 40 }}>
        <a href={primaryHref} className="site-btn site-btn--primary">{primary} →</a>
        {secondary && <a href={secondaryHref} className="site-btn">{secondary}</a>}
      </div>
      <div style={{
        marginTop: 56, paddingTop: 24, width: "100%", maxWidth: 720,
        borderTop: "1px solid var(--nh-line)",
        display: "flex", justifyContent: "center",
        fontFamily: "var(--nh-mono)", fontSize: 10, color: "var(--nh-ink-4)", letterSpacing: "0.22em",
        textTransform: "uppercase",
      }}>
        ◇ NEOHELIO (PTY) LTD
      </div>
    </div>
  </section>
);

window.SiteNav = SiteNav;
window.SiteFooter = SiteFooter;
window.SiteEyebrow = SiteEyebrow;
window.SiteStat = SiteStat;
window.SitePlaceholder = SitePlaceholder;
window.SiteImageSlot = SiteImageSlot;
window.SiteCTA = SiteCTA;
