// Shared components — Nav, Footer, Wordmark, simple primitives

const Wordmark = ({ size = 15, color }) => (
  <span className="brand-mark" style={{ fontSize: size, color }}>
    <span className="brand-glyph"><span className="brand-glyph-img"></span></span>
    <span style={{ letterSpacing: "0.2em" }}>7ARAKA</span>
  </span>
);

const Eyebrow = ({ children, color }) => (
  <span className="eyebrow" style={{ color }}>
    <span className="dot"></span>
    {children}
  </span>
);

const Button = ({ children, variant = "primary", size, icon, iconRight, onClick, href, type, style, disabled }) => {
  const cls = `btn btn-${variant} ${size === "lg" ? "btn-lg" : size === "sm" ? "btn-sm" : ""}`;
  const inner = (
    <>
      {icon && <Icon name={icon} size={16} />}
      <span>{children}</span>
      {iconRight && <Icon name={iconRight} size={16} />}
    </>
  );
  if (href) return <a className={cls} href={href} style={style} onClick={onClick}>{inner}</a>;
  return <button type={type || "button"} className={cls} onClick={onClick} disabled={disabled} style={{ ...style, ...(disabled ? { opacity: 0.6, pointerEvents: "none" } : {}) }}>{inner}</button>;
};

const ArrowBtn = ({ light, onClick, href, label = "Open" }) => {
  const cls = `btn-arrow ${light ? "light" : ""}`;
  if (href) return <a className={cls} href={href} aria-label={label} onClick={onClick}><Icon name="arrow-up-right" size={16} /></a>;
  return <button className={cls} onClick={onClick} aria-label={label}><Icon name="arrow-up-right" size={16} /></button>;
};

// --- Nav ---
const NAV_ITEMS = [
  { id: "home",         label: "Home" },
  { id: "about",        label: "About" },
  { id: "services",     label: "Services" },
  { id: "testimonials", label: "Testimonials" },
  { id: "contact",      label: "Contact" },
];

const Nav = ({ route, navigate }) => {
  const [menuOpen, setMenuOpen] = React.useState(false);
  const go = (id) => { setMenuOpen(false); navigate(id); };
  return (
    <header className="nav">
      <div className="container-wide nav-inner">
        <a href="#home" onClick={(e) => { e.preventDefault(); go("home"); }}>
          <Wordmark />
        </a>
        <nav className="nav-links">
          {NAV_ITEMS.map((n) => (
            <a
              key={n.id}
              href={`#${n.id}`}
              className={`nav-link ${route === n.id ? "active" : ""}`}
              onClick={(e) => { e.preventDefault(); go(n.id); }}
            >
              {n.label}
            </a>
          ))}
        </nav>
        <div style={{ display: "flex", gap: 8, alignItems: "center" }}>
          <Button variant="accent" size="sm" onClick={() => go("services")}>
            Apply
          </Button>
          <button
            className="nav-burger"
            aria-label={menuOpen ? "Close menu" : "Open menu"}
            aria-expanded={menuOpen}
            onClick={() => setMenuOpen((o) => !o)}
          >
            <Icon name={menuOpen ? "x" : "menu"} size={18} />
          </button>
        </div>
      </div>
      <nav className={`nav-mobile ${menuOpen ? "open" : ""}`}>
        {NAV_ITEMS.map((n) => (
          <a
            key={n.id}
            href={`#${n.id}`}
            className={`nav-mobile-link ${route === n.id ? "active" : ""}`}
            onClick={(e) => { e.preventDefault(); go(n.id); }}
          >
            {n.label}
          </a>
        ))}
      </nav>
    </header>
  );
};

// --- Footer ---
const Footer = ({ navigate }) => (
  <footer className="footer">
    <div className="container-wide">
      <div className="footer-grid">
        <div>
          <Wordmark />
          <p className="text-body" style={{ marginTop: 14, maxWidth: 320 }}>
            Health performance coaching, built on Movement, Discipline, Mindset, and Spiritual Growth.
          </p>
          <div style={{ display: "flex", gap: 8, marginTop: 18 }}>
            <a className="btn btn-ghost btn-sm" href="https://www.instagram.com/coach.bido" target="_blank" rel="noopener" aria-label="Instagram"><Icon name="instagram" size={14} /></a>
            <a className="btn btn-ghost btn-sm" href="https://www.linkedin.com/in/bidomohamed" target="_blank" rel="noopener" aria-label="LinkedIn"><Icon name="linkedin" size={14} /></a>
            <a className="btn btn-ghost btn-sm" href="https://www.tiktok.com/@bido.7arakacoaching" target="_blank" rel="noopener" aria-label="TikTok"><Icon name="tiktok" size={14} /></a>
          </div>
        </div>
        <div className="footer-col">
          <h6>Pages</h6>
          <ul>
            {NAV_ITEMS.map((n) => (
              <li key={n.id}><a href={`#${n.id}`} onClick={(e) => { e.preventDefault(); navigate(n.id); }}>{n.label}</a></li>
            ))}
          </ul>
        </div>
        <div className="footer-col">
          <h6>Services</h6>
          <ul>
            <li><a href="#services" onClick={(e) => { e.preventDefault(); navigate("services"); }}>Rehab &amp; Performance</a></li>
            <li><a href="#services" onClick={(e) => { e.preventDefault(); navigate("services"); }}>Personal Coaching</a></li>
            <li><a href="#services" onClick={(e) => { e.preventDefault(); navigate("services"); }}>Online Coaching</a></li>
            <li><a href="#services" onClick={(e) => { e.preventDefault(); navigate("services"); }}>40-Day Reset Challenge</a></li>
          </ul>
        </div>
        <div className="footer-col">
          <h6>Contact</h6>
          <ul>
            <li><a href="mailto:info@7araka.co">info@7araka.co</a></li>
            <li><a href="#contact" onClick={(e) => { e.preventDefault(); navigate("contact"); }}>Book a session</a></li>
            <li><a href="#">Amsterdam & Haarlem, NL</a></li>
          </ul>
        </div>
        <div className="footer-col">
          <h6>Resources</h6>
          <ul>
            <li><a href="#">Journal</a></li>
            <li><a href="#">Method</a></li>
            <li><a href="#">FAQ</a></li>
            <li><a href="#">Privacy</a></li>
          </ul>
        </div>
      </div>
      <div className="footer-bottom">
        <span>© 2026 7ARAKA. Based in the Netherlands.</span>
        <span style={{ fontFamily: "var(--font-mono)", fontSize: 12, color: "var(--muted)" }}>
          ح ⸱ movement
        </span>
      </div>
    </div>
  </footer>
);

// --- Stat strip used on home + about ---
const StatsStrip = ({ items }) => (
  <div className="stats">
    {items.map((s, i) => (
      <div className="stat" key={i}>
        <div className="stat-num">{s.num}</div>
        <div className="stat-label">{s.label}</div>
      </div>
    ))}
  </div>
);

// --- Section heading helper ---
const SectionHead = ({ eyebrow, title, kicker, align = "left", maxWidth }) => (
  <div style={{ textAlign: align, maxWidth, marginInline: align === "center" ? "auto" : undefined }}>
    {eyebrow && <Eyebrow>{eyebrow}</Eyebrow>}
    <h2 className="display-xl text-balance" style={{ marginTop: eyebrow ? 14 : 0 }}>{title}</h2>
    {kicker && <p className="text-body-lg text-pretty" style={{ marginTop: 14, maxWidth: 580, marginInline: align === "center" ? "auto" : undefined }}>{kicker}</p>}
  </div>
);

// --- Pillar card ---
const PillarCard = ({ icon, label, title, body, dark }) => (
  <div className={dark ? "card-dark" : "card"} style={{ display: "flex", flexDirection: "column", gap: 12, minHeight: 220 }}>
    <div style={{
      width: 36, height: 36, borderRadius: 8,
      display: "grid", placeItems: "center",
      background: dark ? "rgba(255,255,255,.08)" : "var(--surface-strong)",
      color: dark ? "var(--cursor-primary)" : "var(--ink)"
    }}>
      <Icon name={icon} size={18} />
    </div>
    <div style={{ fontSize: 11, fontWeight: 600, letterSpacing: "0.12em", textTransform: "uppercase", color: dark ? "rgba(255,255,255,.55)" : "var(--muted)" }}>
      {label}
    </div>
    <h4 className="display-sm" style={{ color: dark ? "var(--canvas)" : "var(--ink)" }}>{title}</h4>
    <p style={{ color: dark ? "rgba(255,255,255,.7)" : "var(--body)", fontSize: 14, lineHeight: 1.55 }}>{body}</p>
  </div>
);

// --- CTA band (above footer) ---
const CTABand = ({ navigate, openApply }) => (
  <section style={{ padding: "96px 0" }}>
    <div className="container-wide" style={{ textAlign: "center" }}>
      <h2 className="display-xl text-balance" style={{ maxWidth: 760, margin: "0 auto" }}>
        Train smarter, recover stronger, and live with intent.
      </h2>
      <div style={{ display: "inline-flex", gap: 12, marginTop: 28, flexWrap: "wrap", justifyContent: "center" }}>
        <Button variant="light" onClick={() => navigate("contact")}>Book a call</Button>
        <Button variant="primary" iconRight="arrow-right" onClick={openApply}>Start your program</Button>
      </div>
    </div>
  </section>
);

// --- Page wrapper handles transition ---
const Page = ({ children }) => (
  <main className="page-enter">{children}</main>
);

Object.assign(window, {
  Wordmark, Eyebrow, Button, ArrowBtn,
  Nav, Footer, StatsStrip, SectionHead, PillarCard, CTABand, Page,
  NAV_ITEMS,
});
