/* global React, useViewport, PageIntro, EditorialCarousel, ThreadBadge,
           SpecificationSection, SpecifierDownloads, EnquiryBlock */
/*
 * HextDetail — collection detail page for Hext. Dwell tier.
 * Narrative angle: a hexagonal table on a powder-coated steel base. Cluster
 * three to fill a foyer; specify one for the corner of a hotel suite.
 */

const { useState: useStateHxt, useEffect: useEffectHxt } = React;

const HEXT_SLIDES_BASE = [
  { title: "Hext", image: "images/collections/hext/hero/01.webp", pos: "center bottom" },
  { title: "Hext", image: "images/collections/hext/hero/02.webp", pos: "center top" },
  { title: "Hext", image: "images/collections/hext/hero/03.webp", pos: "center bottom" },
];
const HEXT_SLIDES = (window.IMG && window.IMG.extend) ? window.IMG.extend("hext", "hero", HEXT_SLIDES_BASE) : HEXT_SLIDES_BASE;

function HextCarousel() {
  const vw = useViewport();
  const isMobile = vw < 760;
  const [i, setI] = useStateHxt(0);
  const [paused, setPaused] = useStateHxt(false);
  useEffectHxt(() => {
    if (paused) return;
    const id = setInterval(() => setI((x) => (x + 1) % HEXT_SLIDES.length), 7000);
    return () => clearInterval(id);
  }, [paused]);
  return (
    <section onMouseEnter={() => setPaused(true)} onMouseLeave={() => setPaused(false)}
      style={{ position: "relative", width: "100%", aspectRatio: "16 / 9",
        maxHeight: isMobile ? "82vh" : "90vh", minHeight: isMobile ? 460 : 560,
        overflow: "hidden", background: "#1a1917" }}>
      {HEXT_SLIDES.map((ss, idx) => (
        <div key={idx} style={{ position: "absolute", inset: 0, opacity: idx === i ? 1 : 0, transition: "opacity 1100ms ease" }}>
          <img src={ss.image} srcSet={window.IMG && window.IMG.srcsetFor(ss.image)} sizes={window.IMG && window.IMG.sizes()} alt={ss.title} loading={idx === 0 ? "eager" : "lazy"}
            style={{ width: "100%", height: "100%", objectFit: "cover", objectPosition: ss.pos || "center", display: "block" }} />
        </div>
      ))}
      <div style={{ position: "absolute", inset: 0,
        background: "linear-gradient(to bottom, transparent 50%, rgba(26,25,23,0.55) 100%)", pointerEvents: "none" }} />
      <div style={{ position: "absolute", left: 0, right: 0, bottom: isMobile ? 84 : 100,
        padding: isMobile ? "0 24px" : "0 32px", textAlign: "center", color: "#f5f3ef" }}>
        <h3 style={{ fontFamily: "var(--font-display, Poppins, sans-serif)", fontWeight: 500,
          fontSize: isMobile ? "clamp(20px, 5vw, 26px)" : "clamp(22px, 1.9vw, 32px)",
          lineHeight: 1.18, letterSpacing: "-0.01em", margin: "0 auto", maxWidth: "26ch", textWrap: "balance" }}>
          {HEXT_SLIDES[i].title}
        </h3>
      </div>
      <div style={{ position: "absolute", bottom: isMobile ? 36 : 44, left: 0, right: 0,
        display: "flex", justifyContent: "center", gap: 10 }}>
        {HEXT_SLIDES.map((_, idx) => (
          <button key={idx} onClick={() => setI(idx)} aria-label={`Show slide ${idx + 1}`}
            style={{ width: idx === i ? 24 : 6, height: 2,
              background: idx === i ? "rgba(245,243,239,0.95)" : "rgba(245,243,239,0.4)",
              border: "none", cursor: "pointer", padding: 0,
              transition: "width 320ms ease, background 320ms ease" }} />
        ))}
      </div>
    </section>
  );
}

function HextDetail() {
  const vw = useViewport();
  const isMobile = vw < 720;
  return (
    <>
      <HextCarousel />
      <PageIntro
        eyebrow="Hext · Alexander Lotersztain, 2010"
        title="A hexagonal table collection built on geometry and symmetry."
        body="A table collection that takes the hexagon as its point of departure, celebrating the quiet power of geometric symmetry. Angular and monolithic in form — sitting in equilibrium between the quadrilateral and the round table, offering an architectural alternative to both."
        compact noTopPad
      />

      <section style={{ padding: isMobile ? "56px 20px" : "96px max(24px, 3vw)", maxWidth: 1440, margin: "0 auto" }}>
        <div style={{ display: "grid", gridTemplateColumns: isMobile ? "1fr" : "1fr 1fr", gap: isMobile ? 32 : 48 }}>
          <EditorialCarousel
            slides={[
              { src: "images/collections/hext/pillars/01.webp", alt: "Hext · single hexagonal table", caption: "01 · Geometry" },
              { src: "images/collections/hext/pillars/02.webp", alt: "Hext at San Diego Airport",            caption: "02 · In service" },
              { src: "images/collections/hext/pillars/03.webp", alt: "Hext · counter-height table",    caption: "03 · Heights" },
            ]}
            aspect="3/4"
          />
          <div style={{ alignSelf: "center" }}>
            <div style={{ fontSize: 11, letterSpacing: "0.16em", textTransform: "uppercase", color: "#6c6862", fontWeight: 500, marginBottom: 14 }}>Dwell · Define</div>
            <h2 style={{ fontWeight: 500, fontSize: isMobile ? "clamp(22px, 5.5vw, 28px)" : "clamp(24px, 2.2vw, 32px)", lineHeight: 1.12, letterSpacing: "-0.01em", color: "#1a1917", margin: "0 0 16px 0", maxWidth: "22ch" }}>
              From a single architectural object to clustered, configurable surfaces.
            </h2>
            <p style={{ fontSize: isMobile ? 15 : 16, lineHeight: 1.55, color: "#1a1917", maxWidth: "46ch", margin: 0, fontWeight: 500 }}>
              Available across a range of heights and sizes, Hext adapts to a wide variety of settings — from intimate, single-table moments to high-traffic clustered installations. Paired with Derlot's Prisma collection, the shared geometric language allows the two systems to work seamlessly side by side.
            </p>
          </div>
        </div>
      </section>

      {/* Three features */}
      <section style={{ padding: isMobile ? "64px 20px" : "120px max(24px, 3vw)", maxWidth: 1440, margin: "0 auto" }}>
        <div style={{ maxWidth: 720, marginBottom: isMobile ? 40 : 64 }}>
          <div style={{ fontSize: 11, letterSpacing: "0.16em", textTransform: "uppercase", color: "#6c6862", fontWeight: 500, marginBottom: 14 }}>What Hext does</div>
          <h2 style={{ fontFamily: "var(--font-display, Poppins, sans-serif)", fontWeight: 500, fontSize: isMobile ? "clamp(24px, 6vw, 30px)" : "clamp(26px, 2.6vw, 38px)", lineHeight: 1.12, letterSpacing: "-0.015em", color: "#1a1917", margin: 0, maxWidth: "26ch", textWrap: "balance" }}>
            Three things that hold the line.
          </h2>
        </div>
        <div style={{ display: "grid", gridTemplateColumns: isMobile ? "1fr" : "repeat(3, 1fr)", gap: isMobile ? 48 : 40 }}>
          {[
            { no: "01", kicker: "Geometry", title: "Hexagonal form as a design principle.",
              body: "The hexagon sits between the quadrilateral and the round table — angular without being austere, geometric without being rigid. It encourages equilibrium and intentional occupation, making the collection suited to both productive workspaces and relaxed gathering. As a standalone piece it holds presence as an architectural object; clustered together, the hexagons tessellate into larger, configurable surfaces.",
              image: "images/collections/hext/hero/03.webp", alt: "Hext · hexagonal form" },
            { no: "02", kicker: "Power", title: "Concealed power routing through the base.",
              body: "Hext's hexagonal base houses an internal void that allows power and data to be routed cleanly from a floor box up to the tabletop, with no visible cables. The detail keeps the table's geometric language uncompromised while delivering the connectivity expected of contemporary workspaces, meeting environments and high-performance public interiors.",
              image: "images/collections/hext/feature/01.webp", alt: "Hext · concealed power routing" },
            { no: "03", kicker: "Configurable", title: "Heights, sizes and finish.",
              body: "Offered in a range of heights and sizes — from lower lounge configurations through standard worktable heights to higher perch and café options — allowing the same geometric language to carry across multiple use cases. The base is finished in an extensive range of powder-coated colours, giving specifiers a flexible toolkit to tune the collection to the material and tonal intent of each project.",
              image: "images/collections/hext/feature/02.webp", alt: "Hext · configurable heights" },
          ].map((f) => (
            <div key={f.no}>
              <div style={{ aspectRatio: "4/5", background: f.bg || "#e4e2da", overflow: "hidden", marginBottom: isMobile ? 18 : 24 }}>
                <img src={f.image} srcSet={window.IMG && window.IMG.srcsetFor(f.image)} sizes={window.IMG && window.IMG.sizes()} alt={f.alt} loading="lazy" style={{ width: "100%", height: "100%", objectFit: f.fit || "cover", display: "block" }} />
              </div>
              <div style={{ display: "flex", alignItems: "baseline", gap: 14, marginBottom: 12 }}>
                <div style={{ fontSize: 11, color: "#6c6862", fontWeight: 500, letterSpacing: "0.08em" }}>{f.no}</div>
                <div style={{ height: "0.5px", flex: 1, background: "rgba(26,25,23,0.25)" }} />
                <div style={{ fontSize: 11, letterSpacing: "0.14em", textTransform: "uppercase", color: "#6c6862", fontWeight: 500 }}>{f.kicker}</div>
              </div>
              <h3 style={{ fontFamily: "var(--font-display, Poppins, sans-serif)", fontWeight: 500, fontSize: isMobile ? 19 : 20, lineHeight: 1.22, letterSpacing: "-0.01em", color: "#1a1917", margin: "0 0 10px 0", maxWidth: "20ch" }}>
                {f.title}
              </h3>
              <p style={{ fontSize: 14, lineHeight: 1.6, color: "#6c6862", margin: 0, maxWidth: "38ch" }}>{f.body}</p>
            </div>
          ))}
        </div>
      </section>

      <SpecificationSection
        skuImageBase="images/collections/hext/skus"
        headline="Three sizes at table height. One at counter height."
        meta={[
          ["Design", "Alexander Lotersztain, 2010"],
          ["Sectors", "Corporate · Hospitality · Civic · Education · Retail"],
          ["Environment", "Indoor"],
          ["Warranty", "5 year structural"],
          ["Certifications", "GECA certified"],
          ["Manufactured", "Australia"],
        ]}
        materials="Hexagonal base in powder-coated mild steel with internal void for concealed power and data routing. Top in veneered MDF. Hexagonal footprint dimensions are measured across flats."
        groups={[
          {
            label: "Hexagonal tables",
            note: "Standard table height 720 mm; counter height 925 mm.",
            items: [
              { sku: "HXT-03", name: "Small hexagonal table",       dims: "800 across flats × 720H" },
              { sku: "HXT-04", name: "Medium hexagonal table",      dims: "1040 across flats × 720H" },
              { sku: "HXT-05", name: "Large hexagonal table",       dims: "1300 across flats × 720H" },
              { sku: "HXT-06", name: "Counter-height hexagonal table", dims: "800 across flats × 925H" },
            ],
          },
        ]}
        extras={[
          {
            label: "Base finish",
            rows: [
              { text: "White powder coat" },
              { text: "Black powder coat" },
              { text: "Custom · any colour available" },
            ],
          },
          {
            label: "Top finish",
            rows: [
              { text: "American Oak veneer on MDF" },
            ],
          },
        ]}
        finishHeadline="Powder-coat base in white, black or custom; American Oak veneered top."
      />

      <SpecifierDownloads collection="Hext" />

      {/* Specified in — 2-up (documented installs) */}
      <section style={{ padding: isMobile ? "56px 20px" : "96px max(24px, 3vw)", maxWidth: 1440, margin: "0 auto", borderTop: "0.5px solid rgba(26,25,23,0.18)" }}>
        <div style={{ marginBottom: isMobile ? 24 : 36 }}>
          <div style={{ fontSize: 11, letterSpacing: "0.16em", textTransform: "uppercase", color: "#6c6862", fontWeight: 500, marginBottom: 12 }}>Specified in</div>
          <h2 style={{ fontFamily: "var(--font-display, Poppins, sans-serif)", fontWeight: 500, fontSize: isMobile ? "clamp(22px, 5.5vw, 28px)" : "clamp(24px, 2.2vw, 32px)", lineHeight: 1.12, letterSpacing: "-0.01em", color: "#1a1917", margin: 0, maxWidth: "24ch", textWrap: "balance" }}>
            From an airport terminal to student commons.
          </h2>
        </div>
        <div style={{ display: "grid", gridTemplateColumns: isMobile ? "1fr" : "repeat(2, 1fr)", gap: isMobile ? 28 : 32 }}>
          {[
            { name: "San Diego International Airport", city: "San Diego, USA", year: 2025, category: "Aviation",       image: "images/collections/hext/feature/03.webp" },
            { name: "Student One",                     city: "Brisbane, AUS",  year: 2019, category: "Student living", image: "images/collections/hext/feature/04.webp" },
          ].map((p) => (
            <div key={p.name}>
              <div style={{ aspectRatio: "3/2", background: "#e4e2da", overflow: "hidden" }}>
                <img src={p.image} srcSet={window.IMG && window.IMG.srcsetFor(p.image)} sizes={window.IMG && window.IMG.sizes()} alt={p.name} loading="lazy" style={{ width: "100%", height: "100%", objectFit: "cover", display: "block" }} />
              </div>
              <div style={{ height: "0.5px", background: "rgba(26,25,23,0.18)", marginTop: 14 }} />
              <div style={{ display: "flex", alignItems: "baseline", justifyContent: "space-between", marginTop: 12, gap: 12 }}>
                <div style={{ fontSize: 16, color: "#1a1917" }}>{p.name}</div>
                <div style={{ fontSize: 12, color: "#6c6862", letterSpacing: "0.04em" }}>{[p.city, p.year].filter(Boolean).join(" · ")}</div>
              </div>
              <div style={{ fontSize: 12, color: "#6c6862", letterSpacing: "0.04em", marginTop: 4 }}>{p.category}</div>
            </div>
          ))}
        </div>
      </section>

      <section style={{ padding: isMobile ? "56px 20px" : "96px max(24px, 3vw)", maxWidth: 1440, margin: "0 auto", borderTop: "0.5px solid rgba(26,25,23,0.18)" }}>
        <div style={{ fontSize: 11, letterSpacing: "0.16em", textTransform: "uppercase", color: "#6c6862", fontWeight: 500, marginBottom: 20 }}>Related collections</div>
        <div style={{ display: "grid", gridTemplateColumns: isMobile ? "1fr" : "repeat(3, 1fr)", gap: isMobile ? 32 : 32 }}>
          {(window.COLLECTIONS || []).filter(c => ["picket", "tonne", "twig"].includes(c.slug)).map((c) => (
            <div key={c.slug}>
              <div style={{ aspectRatio: "4/5", background: "#e4e2da", overflow: "hidden" }}>
                {c.image && <img src={c.image} srcSet={window.IMG && window.IMG.srcsetFor(c.image)} sizes={window.IMG && window.IMG.sizes()} alt={c.name} loading="lazy" style={{ width: "100%", height: "100%", objectFit: "cover", display: "block" }} />}
              </div>
              <div style={{ height: "0.5px", background: "rgba(26,25,23,0.18)", marginTop: 14 }} />
              <div style={{ fontSize: 16, color: "#1a1917", marginTop: 12 }}>{c.name}</div>
              <div style={{ marginTop: 10, display: "flex", flexWrap: "wrap", rowGap: 6 }}>
                {c.threads.map(tk => <ThreadBadge key={tk} threadKey={tk} />)}
              </div>
            </div>
          ))}
        </div>
      </section>

      <EnquiryBlock collection="Hext" />
    </>
  );
}

window.HextDetail = HextDetail;
