/* ════════════════════════════════════════════════════════════════
   Product detail page — shared renderer
   Each product HTML sets window.__product_slug, then this script renders it
   ════════════════════════════════════════════════════════════════ */

const HERO_VIDEO = "https://d8j0ntlcm91z4.cloudfront.net/user_38xzZboKViGWJOttwIXH07lWA1P/hf_20260418_080021_d598092b-c4c2-4e53-8e46-94cf9064cd50.mp4";

function ProductPage() {
  const slug = window.__product_slug;
  const p = window.PRODUCT_DATA[slug];
  if (!p) return <div className="p-8 text-white">Product not found.</div>;

  // Build neighbour navigation (prev/next)
  const slugs = Object.keys(window.PRODUCT_DATA);
  const idx = slugs.indexOf(slug);
  const prev = slugs[(idx - 1 + slugs.length) % slugs.length];
  const next = slugs[(idx + 1) % slugs.length];

  return (
    <>
      {/* ─── HERO ─── */}
      <section className="relative w-full h-[90vh] md:h-screen overflow-hidden bg-black">
        <FadingVideo
          src={HERO_VIDEO}
          className="absolute left-1/2 top-0 -translate-x-1/2 object-cover object-top z-0"
          style={{ width: "120%", height: "120%", filter: "brightness(0.45)" }}
        />
        <div className="absolute inset-0 z-10 flex flex-col">
          <Navbar active="products" />
          <div className="flex-1 flex flex-col justify-center items-center px-4 sm:px-8 md:px-16 lg:px-20 pt-24 text-center">
            <motion.div
              initial={{ opacity: 0, filter: "blur(10px)", y: 20 }}
              animate={{ opacity: 1, filter: "blur(0)", y: 0 }}
              transition={{ duration: 0.7, delay: 0.2, ease: "easeOut" }}
              className="liquid-glass inline-flex items-center gap-3 px-4 py-1.5 mb-8"
              style={{ borderRadius: 9999 }}
            >
              <span className="text-[10px] tracking-[0.3em] uppercase text-white/70 font-body">N° {p.no} / 08</span>
              <span className="w-px h-3 bg-white/20"/>
              <span className="font-heading italic text-white/90 text-sm">{p.latin}</span>
            </motion.div>

            <BlurText
              text={`${p.headlineLine1} ${p.headlineLineEm}`}
              className="text-5xl md:text-7xl lg:text-[7rem] font-heading italic text-white leading-[0.85] tight-4 max-w-4xl mx-auto"
              stagger={100}
            />

            <motion.div
              initial={{ opacity: 0, y: 20 }}
              animate={{ opacity: 1, y: 0 }}
              transition={{ duration: 0.7, delay: 1.0 }}
              className="mt-8"
            >
              <h2 className="font-heading italic text-white/80 text-3xl md:text-4xl">{p.name}</h2>
            </motion.div>

            <motion.p
              initial={{ opacity: 0, y: 20 }}
              animate={{ opacity: 1, y: 0 }}
              transition={{ duration: 0.7, delay: 1.2 }}
              className="mt-6 text-sm md:text-base text-white/80 max-w-2xl font-body font-light leading-relaxed"
            >
              {p.description}
            </motion.p>

            <motion.div
              initial={{ opacity: 0, y: 20 }}
              animate={{ opacity: 1, y: 0 }}
              transition={{ duration: 0.7, delay: 1.4 }}
              className="flex items-center gap-6 mt-10"
            >
              <a href="../index.html#contact" className="liquid-glass-strong inline-flex items-center gap-2 px-5 py-2.5 text-sm font-medium text-white" style={{ borderRadius: 9999 }}>
                Request Quote <ArrowUpRight className="h-5 w-5"/>
              </a>
              <a href="#specs" className="inline-flex items-center gap-2 text-sm text-white font-body">
                View Specifications <ArrowUpRight className="h-4 w-4"/>
              </a>
            </motion.div>
          </div>
          <div className="pb-8 px-4 sm:px-8 md:px-16 lg:px-20 flex items-center justify-between text-[10px] font-body tracking-[0.3em] uppercase text-white/60">
            <span>● GreenHarvest · Catalogue</span>
            <span>Lagos · Nigeria</span>
          </div>
        </div>
      </section>

      {/* ─── HERO IMAGE STRIP ─── */}
      <section className="relative bg-black overflow-hidden">
        <motion.div
          initial={{ opacity: 0, filter: "blur(20px)" }}
          whileInView={{ opacity: 1, filter: "blur(0)" }}
          viewport={{ once: true, amount: 0.2 }}
          transition={{ duration: 1.2 }}
          className="relative h-[60vh] md:h-[80vh] overflow-hidden"
        >
          <img src={p.hero} alt={p.name} className="absolute inset-0 w-full h-full object-cover" style={{ filter: "brightness(0.65) saturate(1.05)" }}/>
          <div className="absolute inset-0" style={{ background: "linear-gradient(180deg, transparent 0%, transparent 50%, rgba(0,0,0,0.8) 100%)" }}/>
          <div className="absolute bottom-8 md:bottom-12 left-4 md:left-16">
            <div className="text-[10px] tracking-[0.3em] uppercase text-white/70 font-body mb-2">◆ Photographed in situ</div>
            <div className="font-heading italic text-white/90 text-xl md:text-2xl">{p.latin}</div>
          </div>
        </motion.div>
      </section>

      {/* ─── LONG DESCRIPTION ─── */}
      <section className="relative bg-black py-24 px-4 sm:px-8 md:px-16 lg:px-20 overflow-hidden">
        <div className="starfield"></div>
        <div className="relative z-10 max-w-4xl mx-auto">
          <motion.div
            initial={{ opacity: 0, filter: "blur(10px)" }}
            whileInView={{ opacity: 1, filter: "blur(0)" }}
            viewport={{ once: true, amount: 0.3 }}
            transition={{ duration: 0.9 }}
          >
            <div className="text-sm font-body text-white/80 mb-6">// The Story Behind</div>
            <h2 className="font-heading italic text-white text-4xl md:text-6xl tight-3 leading-[0.9] mb-10">
              From soil to vessel,<br/><em>traceable.</em>
            </h2>
            <p className="text-lg md:text-xl text-white/80 font-body font-light leading-relaxed">
              {p.longDesc}
            </p>
          </motion.div>
        </div>
      </section>

      {/* ─── SPECS TABLE ─── */}
      <section id="specs" className="relative bg-black py-24 px-4 sm:px-8 md:px-16 lg:px-20 overflow-hidden">
        <div className="relative z-10 max-w-6xl mx-auto">
          <div className="flex items-end justify-between mb-12 gap-6 flex-wrap">
            <div>
              <div className="text-sm font-body text-white/80 mb-3">// Specifications</div>
              <h2 className="font-heading italic text-white text-4xl md:text-6xl tight-3 leading-[0.88]">The Numbers.</h2>
            </div>
            <div className="liquid-glass px-3.5 py-1.5 text-xs font-medium text-white" style={{ borderRadius: 9999 }}>
              MOQ {p.moq} · Lead {p.leadTime}
            </div>
          </div>

          <div className="liquid-glass overflow-hidden" style={{ borderRadius: "1.25rem" }}>
            <div className="grid grid-cols-1 sm:grid-cols-2 gap-px bg-white/10">
              {p.specs.map((s, i) => (
                <motion.div
                  key={i}
                  initial={{ opacity: 0, y: 20 }}
                  whileInView={{ opacity: 1, y: 0 }}
                  viewport={{ once: true, amount: 0.1 }}
                  transition={{ duration: 0.5, delay: i * 0.04 }}
                  className="bg-black/80 p-6 flex items-center justify-between gap-4"
                >
                  <div className="text-[10px] tracking-[0.3em] uppercase text-white/60 font-body">{s.k}</div>
                  <div className="font-heading italic text-white text-xl md:text-2xl text-right">{s.v}</div>
                </motion.div>
              ))}
            </div>
          </div>
        </div>
      </section>

      {/* ─── APPLICATIONS ─── */}
      <section className="relative bg-black py-24 px-4 sm:px-8 md:px-16 lg:px-20 overflow-hidden">
        <div className="starfield"></div>
        <div className="relative z-10 max-w-6xl mx-auto">
          <div className="text-sm font-body text-white/80 mb-6">// Applications</div>
          <h2 className="font-heading italic text-white text-4xl md:text-6xl tight-3 leading-[0.88] mb-12">
            Where it <em>becomes</em> something.
          </h2>
          <div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-5">
            {p.applications.map((a, i) => (
              <motion.div
                key={i}
                initial={{ opacity: 0, y: 20, filter: "blur(10px)" }}
                whileInView={{ opacity: 1, y: 0, filter: "blur(0)" }}
                viewport={{ once: true, amount: 0.1 }}
                transition={{ duration: 0.6, delay: i * 0.05 }}
                className="liquid-glass p-6 flex items-center gap-4"
                style={{ borderRadius: "1rem" }}
              >
                <div className="text-3xl font-heading italic text-white/30 leading-none w-10 shrink-0">{String(i+1).padStart(2, "0")}</div>
                <div className="font-heading italic text-white text-xl md:text-2xl tight-1">{a}</div>
              </motion.div>
            ))}
          </div>
        </div>
      </section>

      {/* ─── GALLERY ─── */}
      <section className="relative bg-black py-24 px-4 sm:px-8 md:px-16 lg:px-20 overflow-hidden">
        <div className="relative z-10 max-w-7xl mx-auto">
          <div className="text-sm font-body text-white/80 mb-6">// Gallery</div>
          <h2 className="font-heading italic text-white text-4xl md:text-6xl tight-3 leading-[0.88] mb-12">In the field.</h2>
          <div className="grid grid-cols-1 md:grid-cols-3 gap-6">
            {p.gallery.map((g, i) => (
              <motion.div
                key={i}
                initial={{ opacity: 0, filter: "blur(20px)", y: 30 }}
                whileInView={{ opacity: 1, filter: "blur(0)", y: 0 }}
                viewport={{ once: true, amount: 0.1 }}
                transition={{ duration: 0.8, delay: i * 0.1 }}
                className="relative overflow-hidden liquid-glass group"
                style={{ borderRadius: "1.25rem", aspectRatio: "3/4" }}
              >
                <img src={g} alt={`${p.name} ${i+1}`} className="absolute inset-0 w-full h-full object-cover transition-transform duration-1000 group-hover:scale-110" style={{ filter: "brightness(0.75) saturate(0.95)" }}/>
                <div className="absolute bottom-4 left-4 right-4 flex items-end justify-between gap-3">
                  <div className="text-[10px] tracking-[0.3em] uppercase text-white/80 font-body">PL · {String(i+1).padStart(2,"0")}</div>
                  <div className="font-heading italic text-white text-lg">{p.name}</div>
                </div>
              </motion.div>
            ))}
          </div>
        </div>
      </section>

      {/* ─── PREV / NEXT NAV ─── */}
      <section className="relative bg-black py-16 px-4 sm:px-8 md:px-16 lg:px-20 border-t border-white/10">
        <div className="max-w-6xl mx-auto grid grid-cols-1 md:grid-cols-2 gap-6">
          <a href={`${prev}.html`} className="liquid-glass p-6 group hover:bg-white/[0.04] transition" style={{ borderRadius: "1rem" }}>
            <div className="text-[10px] tracking-[0.3em] uppercase text-white/50 font-body mb-3">← Previous</div>
            <div className="font-heading italic text-white text-3xl md:text-4xl tight-1 group-hover:text-white">{window.PRODUCT_DATA[prev].name}</div>
            <div className="text-xs font-body text-white/60 mt-2">{window.PRODUCT_DATA[prev].latin}</div>
          </a>
          <a href={`${next}.html`} className="liquid-glass p-6 text-right group hover:bg-white/[0.04] transition" style={{ borderRadius: "1rem" }}>
            <div className="text-[10px] tracking-[0.3em] uppercase text-white/50 font-body mb-3">Next →</div>
            <div className="font-heading italic text-white text-3xl md:text-4xl tight-1 group-hover:text-white">{window.PRODUCT_DATA[next].name}</div>
            <div className="text-xs font-body text-white/60 mt-2">{window.PRODUCT_DATA[next].latin}</div>
          </a>
        </div>
      </section>

      {/* ─── CTA STRIP ─── */}
      <section className="relative bg-black py-24 px-4 sm:px-8 md:px-16 lg:px-20 overflow-hidden">
        <div className="starfield"></div>
        <div className="relative z-10 max-w-4xl mx-auto text-center">
          <h2 className="font-heading italic text-white text-4xl md:text-6xl tight-3 leading-[0.9] mb-6">
            Move {p.name.toLowerCase()}<br/><em>with conviction.</em>
          </h2>
          <p className="text-base md:text-lg text-white/70 font-body font-light max-w-2xl mx-auto mb-10">
            Get a verified Full Corporate Offer within one business day. Specifications adjustable, payment terms negotiable.
          </p>
          <a href="../index.html#contact" className="liquid-glass-strong inline-flex items-center gap-2 px-7 py-3 text-sm font-medium text-white" style={{ borderRadius: 9999 }}>
            Request Quote <ArrowUpRight className="h-5 w-5"/>
          </a>
        </div>
      </section>

      <Footer/>
      <CallButton callEndpoint="../call.php" bookEndpoint="../book.php" slotsEndpoint="../slots.php"/>
    </>
  );
}

ReactDOM.createRoot(document.getElementById("root")).render(<ProductPage/>);
