/* global React, useViewport, PageIntro, EditorialCarousel, ThreadBadge,
           SpecificationSection, SpecifierDownloads, EnquiryBlock */
/*
 * FitDetail — Fit (2012, designed by Matthew Prince). Configure thread.
 * Powder-coated mild steel shelf top with solid timber frame; six SKUs.
 * Indoor only — quiet bookcase / display piece for civic and education.
 */

const { useState: useStateFit, useEffect: useEffectFit } = React;

const FIT_SLIDES_BASE = [
  { title: "Fit", image: "images/collections/fit/hero/01.webp", fit: "contain", bg: "#ffffff" },
  { title: "Fit", image: "images/collections/fit/hero/02.webp", fit: "contain", bg: "#ffffff" },
  { title: "Fit", image: "images/collections/fit/hero/03.webp" },
];
const FIT_SLIDES = (window.IMG && window.IMG.extend) ? window.IMG.extend("fit", "hero", FIT_SLIDES_BASE) : FIT_SLIDES_BASE;

function FitCarousel() {
  const vw = useViewport();
  const isMobile = vw < 760;
  const [i, setI] = useStateFit(0);
  const [paused, setPaused] = useStateFit(false);
  useEffectFit(() => {
    if (paused) return;
    const id = setInterval(() => setI((x) => (x + 1) % FIT_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" }}>
      {FIT_SLIDES.map((ss, idx) => (
        <div key={idx} style={{ position: "absolute", inset: 0, opacity: idx === i ? 1 : 0, transition: "opacity 1100ms ease", background: ss.bg || "transparent" }}>
          <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: ss.fit || "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" }}>
          {FIT_SLIDES[i].title}
        </h3>
      </div>
      <div style={{ position: "absolute", bottom: isMobile ? 36 : 44, left: 0, right: 0,
        display: "flex", justifyContent: "center", gap: 10 }}>
        {FIT_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 FitDetail() {
  const vw = useViewport();
  const isMobile = vw < 720;
  return (
    <>
      <FitCarousel />
      <PageIntro
        eyebrow="Fit · Matthew Prince, 2012"
        title="A flexible, stackable shelving system for storage and spatial division."
        body="Fit is a flexible and multifunctional shelving system designed to serve as both convenient storage and an architectural partition. Adaptable, stackable and reconfigurable, the collection scales to suit a wide range of interiors and intents — from corporate and hospitality settings to civic, retail and educational environments."
        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/fit/pillars/01.webp", alt: "Fit shelving run with media",   caption: "01 · Frame" },
              { src: "images/collections/fit/pillars/02.webp", alt: "Fit shelving as a green display", caption: "02 · Display" },
              { src: "images/collections/fit/pillars/03.webp",   alt: "Fit shelving, heritage setting",  caption: "03 · Form" },
            ]}
            aspect="3/4"
          />
          <div style={{ alignSelf: "center" }}>
            <div style={{ fontSize: 11, letterSpacing: "0.16em", textTransform: "uppercase", color: "#6c6862", fontWeight: 500, marginBottom: 14 }}>Configure · Indoor</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" }}>
              Fit in quietly, or stand out as architecture.
            </h2>
            <p style={{ fontSize: isMobile ? 15 : 16, lineHeight: 1.55, color: "#1a1917", maxWidth: "46ch", margin: 0, fontWeight: 500 }}>
              Built around a modular logic that is a signature of Derlot's collections, Fit can be tailored to the specific demands of each space. Whether the brief is to fit in quietly or stand out as a defining architectural element, Fit responds with the same considered design language and material restraint.
            </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 Fit 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 roles in one system.
          </h2>
        </div>
        <div style={{ display: "grid", gridTemplateColumns: isMobile ? "1fr" : "repeat(3, 1fr)", gap: isMobile ? 48 : 40 }}>
          {[
            { no: "01", kicker: "Versatile", title: "Storage, partition, impromptu bench.",
              body: "Fit functions equally well as a storage solution, a spatial partition, and an impromptu seating bench — allowing a single product to address several of the most common requirements in contemporary interiors. Lower units offer a casual perch for short conversations or informal gathering.",
              image: "images/collections/fit/feature/01.webp", alt: "Fit configured as storage, partition and bench" },
            { no: "02", kicker: "Modular", title: "Stackable and reconfigurable.",
              body: "Fit's units are designed to be stacked, expanded and reconfigured as spaces evolve. Configurations can be linear, clustered or vertical, supporting a wide range of layouts and footprints. Clients can start small and grow over time, or reconfigure existing installations as operational needs shift.",
              image: "images/collections/fit/feature/02.webp", alt: "Fit reconfigured into a clustered layout" },
            { no: "03", kicker: "Configurable", title: "Tailored to the brief.",
              body: "Specifiers can configure Fit's height, depth, module count and finish to match the brief at hand. The same underlying system delivers a discreet storage solution in one project and a defining architectural partition in another — without departing from the design language of the collection.",
              image: "images/collections/fit/hero/03.webp", alt: "Fit specified in two contrasting briefs" },
          ].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>

      <SpecificationSection
        skuImageBase="images/collections/fit/skus"
        headline="Three sizes. Two unit types. One system."
        meta={[
          ["Design", "Matthew Prince, 2012"],
          ["Sectors", "Corporate · Hospitality · Civic · Education · Retail"],
          ["Environment", "Indoor"],
          ["Warranty", "5 year structural"],
          ["Manufactured", "Australia"],
        ]}
        materials="Shelf top in powder-coated mild steel. Frame in solid timber. Shelving units and base units share matching widths so the system stacks and combines into linear, clustered or vertical configurations."
        groups={[
          {
            label: "Shelving units",
            items: [
              { sku: "FIT-01", name: "Small shelving unit",   dims: "1000 × 390 × 450" },
              { sku: "FIT-02", name: "Medium shelving unit",  dims: "1950 × 395 × 450" },
              { sku: "FIT-03", name: "Large shelving unit",   dims: "2900 × 395 × 450" },
            ],
          },
          {
            label: "Base units",
            items: [
              { sku: "FIT-04", name: "Small base unit",       dims: "1000 × 365 × 150" },
              { sku: "FIT-05", name: "Medium base unit",      dims: "1950 × 365 × 150" },
              { sku: "FIT-06", name: "Large base unit",       dims: "2900 × 365 × 150" },
            ],
          },
        ]}
        extras={[
          {
            label: "Shelf top finishes",
            note: "Powder coat.",
            rows: [
              { text: "White" },
              { text: "Black" },
              { text: "Custom · any colour available" },
            ],
          },
          {
            label: "Frame finishes",
            note: "Solid timber.",
            rows: [
              { text: "American Oak" },
              { text: "Victorian Ash" },
              { text: "Black-stained American Oak" },
              { text: "Black-stained Victorian Ash" },
            ],
          },
        ]}
        finishHeadline="Shelf top in white, black or custom powder-coat. Frame in American Oak, Victorian Ash, or either timber black-stained."
      />

      <SpecifierDownloads collection="Fit" />

      {/* Specified in — 2-up (real Fit 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" }}>
            From a workplace floor to an enterprise hub.
          </h2>
        </div>
        <div style={{ display: "grid", gridTemplateColumns: isMobile ? "1fr" : "1fr 1fr", gap: isMobile ? 28 : 32 }}>
          {[
            { name: "Melbourne Entrepreneurial Centre", city: "Melbourne, Australia", year: null, category: "Workplace", image: "images/collections/fit/feature/03.webp" },
            { name: "Fuji Xerox",                       city: "Sydney, Australia",    year: null, category: "Corporate", image: "images/collections/fit/hero/03.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 => ["pillar", "rio", "homework"].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="Fit" />
    </>
  );
}

window.FitDetail = FitDetail;
