/* global React, useViewport, PageIntro, EditorialCarousel, ThreadBadge,
           SpecificationSection, SpecifierDownloads, EnquiryBlock */
/*
 * BiggieDetail — collection detail page for Biggie (2013). Dwell tier, no configurator.
 * Narrative angle: oversized lounge chair — generous shoulders, hospitality-honest.
 */

const { useState: useStateBg, useEffect: useEffectBg } = React;

const BIGGIE_SLIDES_BASE = [
  { title: "Biggie", image: "images/collections/biggie/hero/01.webp" },
  { title: "Biggie", image: "images/collections/biggie/hero/02.webp" },
  { title: "Biggie", image: "images/collections/biggie/hero/03.webp" },
];
const BIGGIE_SLIDES = (window.IMG && window.IMG.extend) ? window.IMG.extend("biggie", "hero", BIGGIE_SLIDES_BASE) : BIGGIE_SLIDES_BASE;

function BiggieCarousel() {
  const vw = useViewport();
  const isMobile = vw < 760;
  const [i, setI] = useStateBg(0);
  const [paused, setPaused] = useStateBg(false);
  useEffectBg(() => {
    if (paused) return;
    const id = setInterval(() => setI((x) => (x + 1) % BIGGIE_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" }}>
      {BIGGIE_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" }}>
          {BIGGIE_SLIDES[i].title}
        </h3>
      </div>
      <div style={{ position: "absolute", bottom: isMobile ? 36 : 44, left: 0, right: 0,
        display: "flex", justifyContent: "center", gap: 10 }}>
        {BIGGIE_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 BiggieDetail() {
  const vw = useViewport();
  const isMobile = vw < 720;
  return (
    <>
      <BiggieCarousel />
      <PageIntro
        eyebrow="Biggie · Alexander Lotersztain, 2019"
        title="A tub chair reimagined in volume and soft presence."
        body="Biggie draws on the lineage of the classic tub chair, reinterpreted with generous proportion, contemporary form and the long-term performance demanded by premium public interiors. Bold in proportion and soft in form, the design holds presence in a room without dominating it — anchoring lounge environments with a relaxed, generous sensibility."
        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/biggie/pillars/01.webp",   alt: "Biggie · tub form, front",          caption: "01 · Form" },
              { src: "images/collections/biggie/pillars/02.webp", alt: "Biggie with oak side table", caption: "02 · Pairing" },
              { src: "images/collections/biggie/pillars/03.webp",  alt: "Biggie · shoulder and seat detail",   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 }}>Dwell</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" }}>
              Volume as design language.
            </h2>
            <p style={{ fontSize: isMobile ? 15 : 16, lineHeight: 1.55, color: "#1a1917", maxWidth: "46ch", margin: 0, fontWeight: 500 }}>
              Available in single and double seater versions, Biggie embraces volume as its defining design language. The result is a piece that brings warmth and considered scale to airport lounges, hospitality settings and refined corporate interiors — tactile, enduring, and made for long use.
            </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 }}>Key features</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 ideas that shape the chair.
          </h2>
        </div>
        <div style={{ display: "grid", gridTemplateColumns: isMobile ? "1fr" : "repeat(3, 1fr)", gap: isMobile ? 48 : 40 }}>
          {[
            { no: "01", kicker: "Generous proportions", title: "Volume as the foundation.",
              body: "Biggie's volumetric form evolves the tub chair's signature embrace into a contemporary architectural language. Full lines and a generous footprint deliver a chair that is bold in presence and intimate in use. Single and double seater versions allow Biggie to anchor a space alone or in pairs.",
              image: "images/collections/biggie/pillars/04.webp", alt: "Biggie in a walnut-panelled lounge" },
            { no: "02", kicker: "Sprung seats", title: "Comfort engineered for long use.",
              body: "Engineered with sprung seats, Biggie delivers comfort that endures. The construction adds resilience to the seating experience and supports the demands of high-use commercial environments without compromising the softness expected of a true lounge chair.",
              image: "images/collections/biggie/pillars/05.webp", alt: "Biggie · sprung seat construction" },
            { no: "03", kicker: "Two-tone option", title: "Seat and back specified separately.",
              body: "Biggie can be specified with seat and backrest in different fabric or leather combinations, allowing the chair to respond to interior intent. Tonal or contrasting, the two-tone option gives designers a direct way to tailor the piece to its setting.",
              image: "images/collections/biggie/pillars/06.webp", alt: "Biggie · two-tone, in use" },
          ].map((f) => (
            <div key={f.no}>
              <div style={{ aspectRatio: "4/5", background: "#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", objectPosition: f.pos || "center", 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/biggie/skus"
        headline="Two scales. Shared depth and height. COM / COL upholstery."
        meta={[
          ["Design", "Alexander Lotersztain, 2019"],
          ["Sectors", "Aviation · Hospitality · Corporate · Civic"],
          ["Environment", "Indoor"],
          ["Warranty", "5 year structural"],
          ["Certifications", "GECA certified"],
          ["Manufactured", "Australia"],
        ]}
        materials="Sprung seat over Dunlop Enduro® foam with MDF substrate. Manufactured in Australia. Specifier-selected upholstery — COM (Customer's Own Material) or COL (Customer's Own Leather). Two-tone option available: seat and backrest in different fabric or leather combinations."
        groups={[{
          label: "Seating · BBG-01 to BBG-02",
          note: "Both pieces share the same depth (750 mm) and seat height (650 mm).",
          items: [
            { sku: "BBG-01", name: "Armchair",          dims: "820 × 750 × 650" },
            { sku: "BBG-02", name: "Two-seater sofa",   dims: "1,560 × 750 × 650" },
          ],
        }]}
        extras={[
          {
            label: "Specification notes",
            rows: [
              { text: "Two-seater is 1.9× the width of the armchair — pair, run, or specify alone." },
              { text: "Two-tone option · seat and backrest specified in different fabric or leather." },
              { text: "Suitable for residential and commercial environments.", muted: true },
            ],
          },
          {
            label: "Upholstery",
            rows: [
              { text: "COM · Customer's Own Material (fabric)." },
              { text: "COL · Customer's Own Leather." },
            ],
          },
        ]}
        finishHeadline="COM / COL upholstery, single or two-tone specification."
      />

      {/* Specified in — real Biggie installations */}
      <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" }}>
            Specified in premium corporate interiors.
          </h2>
        </div>
        <div style={{ display: "grid", gridTemplateColumns: isMobile ? "1fr" : "1fr 1fr", gap: isMobile ? 28 : 32 }}>
          {[
            { name: "BNY Mellon · Gilead",     city: "New York, USA", year: 2024, category: "Corporate", image: "images/collections/biggie/pillars/07.webp", pos: "center" },
          ].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", objectPosition: p.pos || "center", 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>

      <SpecifierDownloads collection="Biggie" />

      <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 => ["mochi", "cup", "cocoon"].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="Biggie" />
    </>
  );
}

window.BiggieDetail = BiggieDetail;
