/* global React, useViewport, PageIntro, EditorialCarousel, ThreadBadge,
           SpecificationSection, SpecifierDownloads, EnquiryBlock */
/*
 * PillarDetail — Pillar (2021, Alexander Lotersztain). Configure + Endure.
 *
 * A table system built on the Australian cattle-rail extrusion — strong,
 * unyielding, and reframed as the structural backbone of a modular table
 * family. 9 SKUs across 4-leg, 6-leg and 8-leg rectangles, a standing-height
 * 4-leg, and two circles. Variable sizing within each SKU. Indoor only.
 * GECA certified. Made in Australia. Connectivity by OE Elsafe.
 */

const { useState: useStatePlr, useEffect: useEffectPlr } = React;

const PLR_SLIDES_BASE = [
  { title: "Pillar", image: "images/collections/pillar/hero/01.webp", pos: "center bottom" },
  { title: "Pillar", image: "images/collections/pillar/hero/02.webp" },
  { title: "Pillar", image: "images/collections/pillar/hero/03.webp" },
  { title: "Pillar", image: "images/collections/pillar/hero/04.webp" },
];
const PLR_SLIDES = (window.IMG && window.IMG.extend) ? window.IMG.extend("pillar", "hero", PLR_SLIDES_BASE) : PLR_SLIDES_BASE;

function PillarCarousel() {
  const vw = useViewport();
  const isMobile = vw < 760;
  const [i, setI] = useStatePlr(0);
  const [paused, setPaused] = useStatePlr(false);
  useEffectPlr(() => {
    if (paused) return;
    const id = setInterval(() => setI((x) => (x + 1) % PLR_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" }}>
      {PLR_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" }}>
          {PLR_SLIDES[i].title}
        </h3>
      </div>
      <div style={{ position: "absolute", bottom: isMobile ? 36 : 44, left: 0, right: 0,
        display: "flex", justifyContent: "center", gap: 10 }}>
        {PLR_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 PillarDetail() {
  const vw = useViewport();
  const isMobile = vw < 720;
  return (
    <>
      <PillarCarousel />
      <PageIntro
        eyebrow="Pillar · Alexander Lotersztain, 2021"
        title="A table system built on the Australian cattle-rail extrusion."
        body="An archetypically Australian object — the cattle-rail extrusion — reframed as the structural heart of a refined, modular table system. Strong and unyielding, with the structural intelligence to scale from individual workstations through to large boardroom and video-conferencing tables. Modest in expression, confident in build."
        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/pillar/pillars/01.webp",    alt: "Pillar scaled to a university hall", caption: "01 · Scale" },
              { src: "images/collections/pillar/pillars/02.webp", alt: "Pillar cable routing to floor box",   caption: "02 · Routing" },
              { src: "images/collections/pillar/pillars/03.webp", alt: "Pillar oak top and white leg",        caption: "03 · Detail" },
            ]}
            aspect="3/4"
          />
          <div style={{ alignSelf: "center" }}>
            <div style={{ fontSize: 11, letterSpacing: "0.16em", textTransform: "uppercase", color: "#6c6862", fontWeight: 500, marginBottom: 14 }}>Configure · Endure</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 workstation to a 9-metre boardroom.
            </h2>
            <p style={{ fontSize: isMobile ? 15 : 16, lineHeight: 1.55, color: "#1a1917", maxWidth: "46ch", margin: 0, fontWeight: 500 }}>
              Variable sizing within each SKU lets Pillar specify across the whole spec — 4-leg square and rectangular tables, 6-leg and 8-leg rectangles up to 9000 mm long, two circular tables to Ø 2400, and a height-adjustable standing-height variant. Same frame language across the whole project.
            </p>
          </div>
        </div>
      </section>

      <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 Pillar 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 Pillar does well.
          </h2>
        </div>
        <div style={{ display: "grid", gridTemplateColumns: isMobile ? "1fr" : "repeat(3, 1fr)", gap: isMobile ? 48 : 40 }}>
          {[
            { no: "01", kicker: "Cattle-rail extrusion", title: "Australian, structural, honest.", body: "Pillar's frame is built around the cattle-rail extrusion — robust, archetypically Australian, and reinterpreted here as the structural backbone of a refined system. Industrial origin acknowledged rather than disguised." },
            { no: "02", kicker: "Concealed connectivity", title: "Power and data, out of sight.",  body: "Concealed cable pathways route power and data from the floor box up through the leg into integrated trays beneath the tabletop. Connectivity by OE Elsafe — soft wiring, sockets, PIXEL and PANDORA power units, ELSAFE wire grid." },
            { no: "03", kicker: "Bespoke configurations", title: "Beyond standard rectangles.",     body: "The extrusion's strength supports highly customisable configurations — large boardrooms, triangular video-conferencing layouts, project-specific geometries. Derlot collaborates directly with project teams to translate frame capability into custom solutions." },
          ].map((f) => (
            <div key={f.no}>
              <div style={{ aspectRatio: "4/5", background: "#e4e2da", overflow: "hidden", marginBottom: isMobile ? 18 : 24 }}>
                <img src={{ "01": "images/_legacy/collections/plr-leg-detail.webp", "02": "images/_legacy/collections/plr-laptop.webp", "03": "images/collections/pillar/hero/04.webp" }[f.no]} alt={f.title} loading="lazy" style={{ width: "100%", height: "100%", objectFit: "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/pillar/skus"
        headline="Nine SKUs. Variable sizing within each."
        meta={[
          ["Design", "Alexander Lotersztain, 2021"],
          ["Sectors", "Corporate · Hospitality · Civic · Education"],
          ["Environment", "Indoor"],
          ["Warranty", "5 year structural"],
          ["Certifications", "GECA certified"],
          ["Connectivity", "OE Elsafe"],
          ["Manufactured", "Australia"],
        ]}
        materials="Frame: powder-coated mild steel with powder-coated mild steel or solid timber legs (American Oak or American Walnut). Table tops: veneered MDF or laminated structural board with matching ABS edge. Concealed cable routing through the cattle-rail extrusion."
        groups={[
          {
            label: "4-leg tables — square & rectangle",
            items: [
              { sku: "PLR-01", name: "4-leg, square & rectangle",   dims: "800–2400 × 1200–3000 × 750 h" },
            ],
          },
          {
            label: "6-leg tables — rectangle",
            items: [
              { sku: "PLR-02", name: "6-leg, rectangle",            dims: "1600–4800 × 1200–1800 × 750 h" },
              { sku: "PLR-03", name: "6-leg, rectangle (extended)", dims: "2400–6000 × 1200–1800 × 750 h" },
            ],
          },
          {
            label: "8-leg tables — rectangle",
            items: [
              { sku: "PLR-04", name: "8-leg, rectangle",            dims: "2400–7200 × 1200–1800 × 750 h" },
              { sku: "PLR-05", name: "8-leg, rectangle (max)",      dims: "3600–9000 × 1200–1800 × 750 h" },
              { sku: "PLR-06", name: "8-leg, rectangle (custom)",   dims: "Custom sizing · 750 h · conference scale" },
            ],
          },
          {
            label: "Standing-height table",
            items: [
              { sku: "PLR-07", name: "Standing-height, 4-leg",      dims: "800–2400 × 900 × 750–1050 h" },
            ],
          },
          {
            label: "Circular tables",
            items: [
              { sku: "PLR-08", name: "4-leg, circle (medium)",      dims: "Ø 1100–1500 × 750 h" },
              { sku: "PLR-09", name: "4-leg, circle (large)",       dims: "Ø 1500–2400 × 750 h" },
            ],
          },
        ]}
        extras={[
          {
            label: "Frame & steel legs — powder coat",
            rows: [
              { text: "White" },
              { text: "Black" },
              { text: "Custom (any colour)", muted: true },
            ],
          },
          {
            label: "Solid timber legs",
            rows: [
              { text: "American Oak" },
              { text: "American Walnut" },
            ],
          },
          {
            label: "Table top — veneer",
            rows: [
              { text: "American Oak veneer" },
              { text: "American Walnut veneer" },
            ],
          },
          {
            label: "Table top — laminate",
            note: "Matching ABS edge.",
            rows: [
              { text: "White laminate" },
              { text: "Black laminate" },
            ],
          },
          {
            label: "Power & data — OE Elsafe",
            note: "In collaboration with OE Electrics Group. Consult pricelist.",
            rows: [
              { text: "Cable reticulation systems" },
              { text: "Socket integration" },
              { text: "PIXEL power units" },
              { text: "PANDORA power units" },
              { text: "ELSAFE wire grid" },
            ],
          },
        ]}
        finishHeadline="Steel or timber legs paired with veneer or laminate tops, with concealed power and data routing throughout."
      />

      <SpecifierDownloads collection="Pillar" />

      {/* Specified in — Arthur Street Studio (documented install) */}
      <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: isMobile ? 24 : 36 }}>Specified in</div>
        <div style={{ display: "grid", gridTemplateColumns: isMobile ? "1fr" : "1fr 1fr", gap: isMobile ? 24 : 48, alignItems: "center" }}>
          <div style={{ aspectRatio: "4/5", background: "#e4e2da", overflow: "hidden" }}>
            <img src="images/_legacy/projects/plr-arthur.webp" alt="Pillar at Arthur Street Studio" loading="lazy" style={{ width: "100%", height: "100%", objectFit: "cover", display: "block" }} />
          </div>
          <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: "20ch", textWrap: "balance" }}>
              Arthur Street Studio
            </h2>
            <p style={{ fontSize: isMobile ? 15 : 16, lineHeight: 1.6, color: "#4a4640", maxWidth: "42ch", marginTop: 16 }}>
              A black cattle-rail Pillar bench anchors the studio's working floor — the extrusion frame carrying soft-wired power and data along its length against raw brick and a blush curtain.
            </p>
            <div style={{ display: "flex", gap: 28, marginTop: 24, flexWrap: "wrap" }}>
              {[["Location", "Brisbane, AUS"], ["Year", "2024"], ["Sector", "Workplace"]].map(([k, v]) => (
                <div key={k}>
                  <div style={{ fontSize: 10, letterSpacing: "0.14em", textTransform: "uppercase", color: "#8b877f", marginBottom: 5 }}>{k}</div>
                  <div style={{ fontSize: 14, color: "#1a1917" }}>{v}</div>
                </div>
              ))}
            </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 => ["rio", "fit", "guell"].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="Pillar" />
    </>
  );
}

window.PillarDetail = PillarDetail;
