/* global React, useViewport, PageIntro, EditorialCarousel, ThreadBadge,
           SpecificationSection, SpecifierDownloads, EnquiryBlock */
/*
 * MochiDetail — collection detail page for Mochi (2020, Alexander Lotersztain).
 *
 * Mochi is a modular seating collection: five seating elements (squares + back-
 * supported modules) plus two companion tables. Named after the soft Japanese
 * rice cake — pared-back, poetic silhouette that arranges into a wide range of
 * configurations. Dwell + Configure threads.
 *
 * Indoor only. GECA certified. 5-yr structural. Made in Australia + Poland.
 */

const { useState: useStateMoC, useEffect: useEffectMoC } = React;

const MOCHI_SLIDES_BASE = [
  { title: "Mochi", image: "images/collections/mochi/hero/01.webp" },
  { title: "Mochi", image: "images/collections/mochi/hero/02.webp" },
  { title: "Mochi", image: "images/collections/mochi/hero/03.webp" },
  { title: "Mochi", image: "images/collections/mochi/hero/04.webp" },
  { title: "Mochi", image: "images/collections/mochi/hero/05.webp" },
];
const MOCHI_SLIDES = (window.IMG && window.IMG.extend) ? window.IMG.extend("mochi", "hero", MOCHI_SLIDES_BASE) : MOCHI_SLIDES_BASE;

function MochiCarousel({ hideCaption = false }) {
  const vw = useViewport();
  const isMobile = vw < 760;
  const [i, setI] = useStateMoC(0);
  const [paused, setPaused] = useStateMoC(false);

  useEffectMoC(() => {
    if (paused) return;
    const id = setInterval(() => setI((x) => (x + 1) % MOCHI_SLIDES.length), 7000);
    return () => clearInterval(id);
  }, [paused]);

  const s = MOCHI_SLIDES[i];

  return (
    <section
      onMouseEnter={() => setPaused(true)}
      onMouseLeave={() => setPaused(false)}
      style={{
        position: "relative",
        width: "100%",
        height: isMobile ? "76vh" : "78vh",
        minHeight: isMobile ? 520 : 620,
        maxHeight: isMobile ? "none" : 820,
        overflow: "hidden",
        background: "#1a1917",
      }}
    >
      {MOCHI_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: hideCaption
          ? "linear-gradient(to bottom, transparent 70%, rgba(26,25,23,0.35) 100%)"
          : "linear-gradient(to bottom, transparent 50%, rgba(26,25,23,0.55) 100%)",
        pointerEvents: "none",
      }} />

      {!hideCaption && (
      <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",
        }}>
          {s.title}
        </h3>
      </div>
      )}

      <div style={{
        position: "absolute",
        bottom: isMobile ? 36 : 44,
        left: 0, right: 0,
        display: "flex", justifyContent: "center", gap: 10,
      }}>
        {MOCHI_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 MochiDetail() {
  const vw = useViewport();
  const isMobile = vw < 720;

  return (
    <>
      <MochiCarousel />

      <PageIntro
        eyebrow="Mochi · Alexander Lotersztain, 2020"
        title="A modular seating collection, named after the soft Japanese rice cake."
        body="Five seating elements that arrange into a wide range of configurations, paired with two companion tables. Mochi's pared-back, poetic silhouette reads cleanly from every angle — soft and smooth in the Japanese sense, blending into corporate, hospitality, civic and education interiors."
        compact
        noTopPad
      />

      {/* Editorial pair */}
      <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/mochi/pillars/01.webp",       alt: "Mochi · top-down flatlay of the full module family", caption: "01 · System" },
              { src: "images/collections/mochi/pillars/02.webp",   alt: "Mochi · upholstery and form detail",   caption: "02 · Detail" },
              { src: "images/collections/mochi/pillars/03.webp", alt: "Mochi · clustered modules at one.nz", caption: "03 · Form" },
              { src: "images/collections/mochi/pillars/04.webp",   alt: "Mochi · marble companion table",       caption: "04 · Table" },
            ]}
            aspect="3/4"
          />
          <div style={{ alignSelf: "center" }}>
            <div style={{ fontSize: 11, letterSpacing: "0.16em", textTransform: "uppercase", color: "#6c6862", fontWeight: 500, marginBottom: 14 }}>Dwell · Configure</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" }}>
              Five elements. Many ways to sit.
            </h2>
            <p style={{ fontSize: isMobile ? 15 : 16, lineHeight: 1.55, color: "#1a1917", maxWidth: "46ch", margin: 0, fontWeight: 500 }}>
              Mochi is built around five seating modules — single and double squares, plus three back-supported variants — that combine to create intimate clusters, generous lounges, or extended runs. Two companion tables (a circular side and a square coffee) complete the family. The system adapts through arrangement rather than imposing a single way of being used.
            </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 Mochi 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 Mochi does well.
          </h2>
        </div>

        <div style={{ display: "grid", gridTemplateColumns: isMobile ? "1fr" : "repeat(3, 1fr)", gap: isMobile ? 48 : 40 }}>
          {[
            {
              no: "01",
              kicker: "Modular",
              title: "Five elements, many configurations.",
              body: "Single and double 900 mm seats, plus three 1025 mm back-supported variants. Specify a single perch, a face-to-face pairing, or a full run that anchors a lounge — the modular logic carries across.",
              image: "images/collections/mochi/feature/01.webp",
              alt: "Mochi modules in multiple configurations",
            },
            {
              no: "02",
              kicker: "Pared-back form",
              title: "Soft, resolved, quietly present.",
              body: "Mochi's silhouette is reductive rather than decorative. The plush contours invite intuitive use, and the well-proportioned backrest doubles as a casual perching surface — supporting sitting, perching, gathering and pausing without competing with the architecture.",
              image: "images/collections/mochi/feature/02.webp",
              alt: "Mochi pared-back silhouette in a corporate lobby",
            },
            {
              no: "03",
              kicker: "Companion tables",
              title: "Two surfaces in the same family.",
              body: "A Ø 650 circular side table at 320 mm and an 800 mm-square coffee table at 400 mm — both sized to land beside the seating modules. Powder-coated mild-steel base, solid American Oak or Walnut top.",
              image: "images/collections/mochi/feature/03.webp",
              alt: "Mochi companion table beside seating modules",
            },
          ].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: "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>

      {/* Specification */}
      <SpecificationSection
        skuImageBase="images/collections/mochi/skus"
        headline="Five seating modules. Two companion tables."
        meta={[
          ["Design", "Alexander Lotersztain, 2020"],
          ["Sectors", "Hospitality · Corporate · Civic · Education"],
          ["Environment", "Indoor"],
          ["Warranty", "5 year structural"],
          ["Certifications", "GECA certified"],
          ["Manufactured", "Australia & Poland"],
        ]}
        materials="Seating: Dunlop Enduro® foam over MDF substrate, upholstered in specifier-selected commercial fabric (COM, fabric only — no leather option). Seat height 450 mm across all modules. Tables: powder-coated mild-steel base with solid timber top."
        groups={[
          {
            label: "Seating modules — 900 mm width",
            items: [
              { sku: "MCH-01", name: "Single seating module",        dims: "900 × 900 × 450 h" },
              { sku: "MCH-02", name: "Double seating module",        dims: "900 × 1700 × 450 h" },
            ],
          },
          {
            label: "Seating modules with back — 1025 mm width",
            note: "Back height 700 mm.",
            items: [
              { sku: "MCH-03", name: "Seating module with back",     dims: "1025 × 1500 × 700 h" },
              { sku: "MCH-04", name: "Wide double with back",        dims: "1025 × 2100 × 700 h" },
              { sku: "MCH-05", name: "Wide double with back, variant", dims: "1025 × 2100 × 700 h" },
            ],
          },
          {
            label: "Companion tables",
            items: [
              { sku: "MCH-11", name: "Circular side table",          dims: "Ø 650 × 320 h" },
              { sku: "MCH-12", name: "Square coffee table",          dims: "800 × 800 × 400 h" },
            ],
          },
        ]}
        extras={[
          {
            label: "Upholstery",
            note: "Customer's Own Material — fabric only, no leather option.",
            rows: [
              { text: "Specifier-selected commercial fabric across the full Mochi seating range." },
            ],
          },
          {
            label: "Table base — powder coat",
            rows: [
              { text: "White" },
              { text: "Black" },
              { text: "Custom colour", muted: true },
            ],
          },
          {
            label: "Table top — solid timber",
            rows: [
              { text: "American Oak" },
              { text: "American Walnut" },
              { text: "Custom material on request — past commissions in marble and stone", muted: true },
            ],
          },
        ]}
        finishHeadline="COM upholstery across all seating, with timber + powder-coat finishes carried through to the companion tables."
      />

      {/* Specified in — 2-up */}
      <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 corporate lobbies to design showrooms.
          </h2>
        </div>
        <div style={{ display: "grid", gridTemplateColumns: isMobile ? "1fr" : "1fr 1fr", gap: isMobile ? 28 : 32 }}>
          {[
            { name: "Jubilee Place",               city: "Brisbane, AUS", year: 2022, category: "Corporate", image: "images/collections/mochi/cover.webp" },
            { name: "one.nz, Daldy Street",         city: "Auckland, NZ",  year: 2025, category: "Corporate", image: "images/collections/mochi/feature/05.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}</div>
              </div>
              <div style={{ fontSize: 12, color: "#6c6862", letterSpacing: "0.04em", marginTop: 4 }}>{p.category}</div>
            </div>
          ))}
        </div>
      </section>

      <SpecifierDownloads collection="Mochi" />

      {/* Related collections */}
      <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 => ["caterpillar", "tetromino-soft", "biggie"].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="Mochi" />
    </>
  );
}

window.MochiDetail = MochiDetail;
