// ============================================================================
// geneltec-page-shell.jsx — shared components for all inner pages
// InnerNav · PageHero · Footer · PageLayout
// ============================================================================
const { useState, useEffect, useRef } = React;
const { motion, Icon, ChevronRight, ArrowUpRight, Zap, Phone } = window;

// ---- Extra icons -----------------------------------------------------------
const FileText = (p) => (
  <Icon {...p}>
    <path d="M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z"/>
    <path d="M14 2v4a2 2 0 0 0 2 2h4"/><path d="M10 9H8"/><path d="M16 13H8"/><path d="M16 17H8"/>
  </Icon>
);
const HelpCircle = (p) => (
  <Icon {...p}>
    <circle cx="12" cy="12" r="10"/>
    <path d="M9.09 9a3 3 0 0 1 5.83 1c0 2-3 3-3 3"/><path d="M12 17h.01"/>
  </Icon>
);
const Layers = (p) => (
  <Icon {...p}>
    <path d="m12.83 2.18a2 2 0 0 0-1.66 0L2.6 6.08a1 1 0 0 0 0 1.83l8.58 3.91a2 2 0 0 0 1.66 0l8.58-3.9a1 1 0 0 0 0-1.83Z"/>
    <path d="m22 17.65-9.17 4.16a2 2 0 0 1-1.66 0L2 17.65"/>
    <path d="m22 12.65-9.17 4.16a2 2 0 0 1-1.66 0L2 12.65"/>
  </Icon>
);
const Grid = (p) => (
  <Icon {...p}>
    <rect width="7" height="7" x="3" y="3" rx="1"/><rect width="7" height="7" x="14" y="3" rx="1"/>
    <rect width="7" height="7" x="14" y="14" rx="1"/><rect width="7" height="7" x="3" y="14" rx="1"/>
  </Icon>
);
const Users = (p) => (
  <Icon {...p}>
    <path d="M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2"/>
    <circle cx="9" cy="7" r="4"/>
    <path d="M22 21v-2a4 4 0 0 0-3-3.87"/><path d="M16 3.13a4 4 0 0 1 0 7.75"/>
  </Icon>
);
const Mail = (p) => (
  <Icon {...p}>
    <rect width="20" height="16" x="2" y="4" rx="2"/>
    <path d="m22 7-8.97 5.7a1.94 1.94 0 0 1-2.06 0L2 7"/>
  </Icon>
);
const MapPin = (p) => (
  <Icon {...p}>
    <path d="M20 10c0 4.993-5.539 10.193-7.399 11.799a1 1 0 0 1-1.202 0C9.539 20.193 4 14.993 4 10a8 8 0 0 1 16 0"/>
    <circle cx="12" cy="10" r="3"/>
  </Icon>
);
const Globe = (p) => (
  <Icon {...p}>
    <circle cx="12" cy="12" r="10"/>
    <path d="M12 2a14.5 14.5 0 0 0 0 20 14.5 14.5 0 0 0 0-20"/><path d="M2 12h20"/>
  </Icon>
);
const Check = (p) => (<Icon {...p}><polyline points="20 6 9 17 4 12"/></Icon>);
const Home = (p) => (
  <Icon {...p}>
    <path d="m3 9 9-7 9 7v11a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z"/>
    <polyline points="9 22 9 12 15 12 15 22"/>
  </Icon>
);

// ---- Navigation pages list -------------------------------------------------
const NAV_PAGES = [
  { label: "Services",  href: "services.html" },
  { label: "Portfolio", href: "portfolio.html" },
  { label: "Processus", href: "processus.html" },
  { label: "À propos",  href: "about.html" },
  { label: "FAQ",       href: "faq.html" },
  { label: "Brochure",  href: "brochure.html" },
];

function getCurrentPage() {
  if (typeof window === "undefined") return "";
  return window.location.pathname.split("/").pop() || "index.html";
}

// ============================================================================
// InnerNav — solid dark navbar for inner pages
// ============================================================================
function InnerNav() {
  const [open, setOpen] = useState(false);
  const current = getCurrentPage();
  return (
    <header style={{ background: "var(--ink-900)", borderBottom: "1px solid rgba(255,255,255,0.08)" }}>
      <nav className="flex items-center justify-between px-5 md:px-8 lg:px-12 h-16 max-w-[1536px] mx-auto">
        {/* Logo */}
        <a href="index.html" className="flex items-center gap-2 shrink-0">
          <span className="flex items-center px-3 py-1.5 rounded-full" style={{ background: "rgba(255,255,255,0.94)" }}>
            <img src="project/assets/logo-new.png" alt="Geneltec" className="h-7 w-auto block" />
          </span>
        </a>

        {/* Desktop links */}
        <ul className="hidden md:flex items-center gap-1">
          {NAV_PAGES.map((p) => {
            const active = current === p.href;
            return (
              <li key={p.href}>
                <a
                  href={p.href}
                  className="px-3.5 py-2 rounded-full text-[13px] font-medium transition-colors whitespace-nowrap"
                  style={active
                    ? { color: "#fff", background: "rgba(26,182,224,0.18)", borderBottom: "1px solid rgba(26,182,224,0.4)" }
                    : { color: "rgba(255,255,255,0.65)" }}
                >
                  {p.label}
                </a>
              </li>
            );
          })}
        </ul>

        {/* CTA */}
        <div className="flex items-center gap-3">
          <a
            href="contact.html"
            className="gl-cta flex items-center rounded-full pl-2 pr-4 py-1.5 gap-2 whitespace-nowrap"
          >
            <div className="bg-white/25 p-1 rounded-full">
              <ArrowUpRight className="w-4 h-4 text-white" strokeWidth={2} />
            </div>
            <span className="text-sm font-semibold">Devis gratuit</span>
          </a>

          {/* Mobile hamburger */}
          <button
            onClick={() => setOpen(!open)}
            className="md:hidden w-9 h-9 flex flex-col items-center justify-center gap-1.5"
            aria-label="Menu"
          >
            {[0, 1, 2].map((i) => (
              <span key={i} className="block w-5 h-px rounded-full transition-all" style={{ background: "rgba(255,255,255,0.75)" }} />
            ))}
          </button>
        </div>
      </nav>

      {/* Mobile dropdown */}
      {open && (
        <div className="md:hidden border-t border-white/08 py-3 px-5" style={{ background: "var(--ink-800)" }}>
          {NAV_PAGES.map((p) => (
            <a
              key={p.href}
              href={p.href}
              className="block py-3 text-[14px] font-medium border-b border-white/06"
              style={{ color: current === p.href ? "var(--brand-400)" : "rgba(255,255,255,0.75)" }}
            >
              {p.label}
            </a>
          ))}
          <a href="contact.html" className="block py-3 text-[14px] font-medium" style={{ color: "var(--brand-400)" }}>
            Devis gratuit →
          </a>
        </div>
      )}
    </header>
  );
}

// ============================================================================
// PageHero — dark header for inner pages
// ============================================================================
function PageHero({ eyebrow, title, lead, accent }) {
  return (
    <div
      className="relative overflow-hidden py-16 md:py-20 lg:py-24 px-5 md:px-8 lg:px-12"
      style={{ background: "var(--ink-900)" }}
    >
      {/* Grid overlay */}
      <div className="absolute inset-0 opacity-[0.06] pointer-events-none" style={{
        backgroundImage: "linear-gradient(rgba(255,255,255,0.5) 1px,transparent 1px),linear-gradient(90deg,rgba(255,255,255,0.5) 1px,transparent 1px)",
        backgroundSize: "64px 64px"
      }}/>
      {/* Brand glow */}
      <div className="absolute pointer-events-none" style={{
        right: "-10%", top: "-50%", width: "55%", height: "200%",
        background: "radial-gradient(closest-side,rgba(26,182,224,0.20),rgba(26,182,224,0) 70%)",
        filter: "blur(24px)"
      }}/>
      <div className="relative max-w-[1280px] mx-auto">
        <div className="inline-flex items-center gap-2 mb-5">
          <span className="w-6 h-px bg-[var(--brand-400)] opacity-60" />
          <span className="text-[11px] font-semibold uppercase tracking-[0.20em] text-[var(--brand-400)]">{eyebrow}</span>
        </div>
        <h1
          className="font-semibold text-white mb-4"
          style={{ fontSize: "clamp(2rem, 5vw, 4rem)", letterSpacing: "-0.025em", lineHeight: 1.0 }}
        >
          {title}{accent && <span className="text-[var(--brand-400)] italic font-medium"> {accent}</span>}
        </h1>
        {lead && (
          <p className="text-white/65 max-w-[560px]" style={{ fontSize: "clamp(15px,1.1vw,18px)", lineHeight: 1.65 }}>
            {lead}
          </p>
        )}
      </div>
    </div>
  );
}

// ============================================================================
// Footer
// ============================================================================
function FooterCol({ title, items, mono }) {
  return (
    <div>
      <h4 className="text-[10px] uppercase tracking-[0.18em] font-mono font-semibold text-[var(--neutral-500)] mb-4">{title}</h4>
      <ul className="flex flex-col gap-2.5">
        {items.map((it) => (
          <li key={it} className={"text-[14px] text-[var(--ink-900)] hover:text-[var(--brand-600)] cursor-pointer transition-colors " + (mono ? "font-mono text-[13px]" : "")}>{it}</li>
        ))}
      </ul>
    </div>
  );
}

function Footer() {
  return (
    <footer className="px-3 md:px-5 pb-3 md:pb-5 mt-3">
      <div className="rounded-[1.5rem] md:rounded-[2.4rem] p-6 md:p-10 lg:p-12 relative overflow-hidden" style={{ background: "var(--neutral-100)" }}>
        <div className="grid grid-cols-1 md:grid-cols-[2fr_1fr_1fr_1fr] gap-8 md:gap-12">
          <div className="max-w-[340px]">
            <img src="project/assets/logo-new.png" alt="Geneltec" className="h-7 w-auto mb-4" />
            <p className="text-[14px] leading-relaxed text-[var(--neutral-600)]">Solutions électriques et technologiques intégrées. Industriel, tertiaire et résidentiel — partout au Maroc.</p>
            <div className="flex items-center gap-2 mt-5">
              <span className="inline-flex items-center gap-1.5 text-[10px] uppercase tracking-[0.18em] font-mono font-semibold text-[var(--neutral-500)] px-2.5 py-1 rounded-full border border-[var(--border)] bg-white">
                <span className="gl-live-dot inline-block w-1.5 h-1.5 rounded-full" style={{ background: "var(--status-ok)" }} />
                Disponible 24/7
              </span>
            </div>
          </div>
          <FooterCol title="Pages" items={["Services","Portfolio","Processus","À propos","FAQ","Brochure"]} />
          <FooterCol title="Services" items={["Résidentielle","Industrielle","Solaire","Domotique","Sécurité","Automatisation"]} />
          <FooterCol title="Contact" items={["+212 662 12 90 67","geneltec.ouhallab@gmail.com","www.geneltec.ma","Mohammedia, Maroc"]} mono />
        </div>
        <div className="flex flex-col md:flex-row items-start md:items-center justify-between gap-3 mt-10 pt-6" style={{ borderTop: "1px solid var(--border)" }}>
          <span className="text-[11px] font-mono text-[var(--neutral-500)]">© 2026 Geneltec · Smart Technology · Tous droits réservés</span>
          <span className="text-[11px] font-mono text-[var(--neutral-500)]">Mohammedia · Casablanca · Rabat · Marrakech</span>
        </div>
      </div>
    </footer>
  );
}

// ============================================================================
// SectionTag — reusable across pages
// ============================================================================
function SectionTag({ num, label, dark }) {
  return (
    <div
      className={"inline-flex items-center gap-2 px-3 py-1.5 rounded-full text-[10px] uppercase tracking-[0.18em] font-mono font-medium " +
        (dark ? "border-white/15 text-white/65 bg-white/5" : "border-[var(--border)] text-[var(--neutral-500)] bg-[var(--neutral-50)]")}
      style={{ borderWidth: 1, borderStyle: "solid" }}
    >
      <span style={{ color: dark ? "var(--brand-400)" : "var(--brand-600)" }}>{num}</span>
      <span className="w-1 h-1 rounded-full bg-current opacity-40" />
      {label}
    </div>
  );
}

// ============================================================================
// ContactCTA — reusable bottom CTA banner
// ============================================================================
function ContactCTA({ title = "Un projet en tête ?", sub = "Étude offerte · Réponse sous 24h · Partout au Maroc" }) {
  return (
    <section className="px-3 md:px-5 mt-3 mb-3">
      <div
        className="rounded-[1.5rem] md:rounded-[2rem] p-8 md:p-12 lg:p-16 flex flex-col md:flex-row items-center justify-between gap-6 relative overflow-hidden"
        style={{ background: "var(--ink-900)" }}
      >
        <div className="absolute pointer-events-none" style={{ right:"-10%",top:"-50%",width:"50%",height:"200%",background:"radial-gradient(closest-side,rgba(26,182,224,0.25),transparent 70%)",filter:"blur(20px)" }}/>
        <div className="relative">
          <h2 className="text-white font-semibold" style={{ fontSize:"clamp(1.5rem,3vw,2.4rem)", letterSpacing:"-0.02em" }}>{title}</h2>
          <p className="text-white/55 text-[14px] md:text-[15px] font-mono mt-2">{sub}</p>
        </div>
        <a href="contact.html" className="gl-cta relative shrink-0 inline-flex items-center gap-3 rounded-full px-6 py-3.5">
          <span className="text-[14px] font-semibold">Demander un devis</span>
          <ArrowUpRight className="w-4 h-4 text-white" strokeWidth={2} />
        </a>
      </div>
    </section>
  );
}

// Exports
Object.assign(window, { InnerNav, PageHero, Footer, SectionTag, ContactCTA,
  FileText, HelpCircle, Layers, Grid, Users, Mail, MapPin, Globe, Check, Home });
