// shared/Chrome.jsx — Nav, Footer, Hero illustration, Tweaks plumbing for KinCulture
// Loaded on every page. Reads current page from <body data-page="...">.

const { useState, useEffect } = React;

// ---------- Logo ----------
const KCLogo = ({ height = 40, dark = false }) => (
  <span style={{ display: "inline-flex", alignItems: "center", gap: height * 0.28 }}>
    <img
      src="assets/kinculture-seal.png"
      alt="KinCulture seal"
      width={height}
      height={height}
      style={{ display: "block", borderRadius: "50%", flex: "none" }}
    />
    <span style={{ display: "inline-flex", flexDirection: "column", lineHeight: 1 }}>
      <span style={{ fontFamily: "Fraunces, Georgia, serif", fontSize: height * 0.55, fontWeight: 500, letterSpacing: "-0.6px", color: dark ? "#FAF7F2" : "#1C3320" }}>KinCulture</span>
      <span style={{ fontFamily: "Inter, sans-serif", fontSize: height * 0.225, fontWeight: 600, letterSpacing: "1.4px", color: dark ? "#A8B89A" : "#7A7060", marginTop: height * 0.12, whiteSpace: "nowrap" }}>ROOTED IN PEOPLE</span>
    </span>
  </span>
);

// ---------- Top Nav ----------
const NAV_ITEMS = [
  { href: "index.html",        label: "Home",          key: "home" },
  { href: "about.html",        label: "About",         key: "about" },
  { href: "courses.html",      label: "Courses",       key: "courses" },
  { href: "benefits.html",     label: "Benefits",      key: "benefits" },
  { href: "contact.html",      label: "Contact",       key: "contact" },
];

const TopNav = ({ active }) => {
  const [scrolled, setScrolled] = useState(false);
  const [open, setOpen] = useState(false);
  useEffect(() => {
    const onScroll = () => setScrolled(window.scrollY > 20);
    onScroll();
    window.addEventListener("scroll", onScroll, { passive: true });
    return () => window.removeEventListener("scroll", onScroll);
  }, []);
  return (
    <nav className={`kc-nav ${scrolled ? "is-scrolled" : ""}`}>
      <div className="kc-nav__inner">
        <a className="kc-nav__brand" href="index.html"><KCLogo height={40}/></a>
        <ul className={`kc-nav__menu ${open ? "is-open" : ""}`}>
          {NAV_ITEMS.map(n => (
            <li key={n.key}>
              <a href={n.href} className={active === n.key ? "is-active" : ""} onClick={() => setOpen(false)}>{n.label}</a>
            </li>
          ))}
        </ul>
        <div className="kc-nav__right">
          <a className="kc-nav__cta" href="contact.html">Partner with us</a>
          <a className="kc-btn kc-btn--primary" href="https://kinculture-client-portal.bubbleapps.io/">Partner Login →</a>
        </div>
        <button className="kc-nav__burger" aria-label="Menu" onClick={() => setOpen(o => !o)}>
          <svg width="22" height="22" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round">
            {open ? <><path d="M6 6 L18 18"/><path d="M18 6 L6 18"/></> : <><path d="M3 6h18"/><path d="M3 12h18"/><path d="M3 18h18"/></>}
          </svg>
        </button>
      </div>
    </nav>
  );
};

// ---------- Footer ----------
const FOOTER_LINKS = {
  Program:  [["About",  "about.html"], ["Courses", "courses.html"], ["Benefits", "benefits.html"]],
  Buyers:   [["For Leadership", "benefits.html"], ["For Behavioral Health Advocates", "benefits.html"], ["Reserve a spot", "contact.html"]],
  Resources:[["The credential", "courses.html#credential"], ["The voice of the supervisor", "#"]],
  Company:  [["Contact", "contact.html"], ["Founder", "about.html#founder"]],
};

const Footer = () => (
  <footer className="kc-footer">
    <div className="kc-footer__top">
      <div className="kc-footer__brand">
        <KCLogo height={48}/>
        <p className="kc-footer__blurb">
          Developing the people who care for people. A credentialed leadership development program for behavioral health leaders.
        </p>
      </div>
      {Object.entries(FOOTER_LINKS).map(([h, links]) => (
        <div key={h} className="kc-footer__col">
          <h6 className="kc-footer__h">{h}</h6>
          {links.map(([l, href]) => <a key={l} href={href}>{l}</a>)}
        </div>
      ))}
    </div>
    <img className="kc-footer__horizon" src="assets/footer-horizon.svg" alt=""/>
    <div className="kc-footer__fine">
      <span>© 2026 KinCulture Co · Lehi, Utah</span>
      <span>Partnerships@KinCultureCo.com · (385) 323-2551</span>
    </div>
  </footer>
);

// ---------- Hero claymation illustration (KC custom, not GTM one) ----------
const KCHeroArt = ({ variant = "mountain" }) => {
  return (
    <img
      src="assets/team-high-five.png"
      alt="A team putting their hands together in the center"
      style={{ width: "100%", height: "100%", objectFit: "cover", objectPosition: "center", display: "block" }}
    />
  );
};

// ---------- Photo placeholder (warm-toned blocks) ----------
const PhotoPlaceholder = ({ label = "Photo placeholder", tone = "sage", src }) => {
  if (src) {
    return (
      <img
        src={src}
        alt={label}
        style={{ width: "100%", height: "100%", objectFit: "cover", objectPosition: "center top", display: "block" }}
      />
    );
  }
  const tones = {
    sage:   { bg: "#A8B89A", fg: "#1C3320", a: "#C8A96E", b: "#D4B896" },
    ochre:  { bg: "#C8A96E", fg: "#1C3320", a: "#A8B89A", b: "#D4B896" },
    peach:  { bg: "#D4B896", fg: "#1C3320", a: "#A8B89A", b: "#8B5A3C" },
    walnut: { bg: "#8B5A3C", fg: "#FAF7F2", a: "#D4B896", b: "#C8A96E" },
    forest: { bg: "#1C3320", fg: "#FAF7F2", a: "#A8B89A", b: "#C8A96E" },
  };
  const t = tones[tone] || tones.sage;
  return (
    <div style={{
      width: "100%", height: "100%", background: t.bg, color: t.fg,
      display: "flex", flexDirection: "column", justifyContent: "space-between",
      padding: 16, fontFamily: "Inter, sans-serif", fontSize: 11, letterSpacing: 0.8,
      textTransform: "uppercase", fontWeight: 600, position: "relative", overflow: "hidden",
    }}>
      {/* abstract clay shapes */}
      <svg width="100%" height="100%" viewBox="0 0 200 240" preserveAspectRatio="xMidYMid slice" style={{ position: "absolute", inset: 0 }}>
        <circle cx="60" cy="80" r="48" fill={t.a} opacity="0.85"/>
        <ellipse cx="160" cy="180" rx="64" ry="48" fill={t.b} opacity="0.8"/>
        <rect x="20" y="160" width="80" height="56" rx="12" fill={t.a} opacity="0.5"/>
      </svg>
      <span style={{ position: "relative", opacity: 0.85 }}>· photo</span>
      <span style={{ position: "relative", opacity: 0.85 }}>{label}</span>
    </div>
  );
};

window.KCLogo = KCLogo;
window.TopNav = TopNav;
window.Footer = Footer;
window.KCHeroArt = KCHeroArt;
window.PhotoPlaceholder = PhotoPlaceholder;
