/* global React, useViewport, PageIntro, EditorialCarousel, ThreadBadge,
           SpecificationSection, SpecifierDownloads, EnquiryBlock */
/*
 * IviDetail — Ivi (2021). Endure thread.
 * Single chair: pressed-plywood seat (veneer or upholstered) on a powder-
 * coated mild-steel frame. Education and civic-meeting specification.
 */

const { useState: useStateIvi, useEffect: useEffectIvi } = React;

const IVI_SLIDES_BASE = [
  { title: "Ivi", image: "images/collections/ivi/hero/01.jpg", pos: "center 68%" },
  { title: "Ivi", image: "images/collections/ivi/hero/02.jpg", pos: "center 70%" },
  { title: "Ivi", image: "images/collections/ivi/hero/03.jpg", pos: "center 72%" },
];
const IVI_SLIDES = (window.IMG && window.IMG.extend) ? window.IMG.extend("ivi", "hero", IVI_SLIDES_BASE) : IVI_SLIDES_BASE;

function IviCarousel() {
  const vw = useViewport();
  const isMobile = vw < 760;
  const [i, setI] = useStateIvi(0);
  const [paused, setPaused] = useStateIvi(false);

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

  const s = IVI_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" }}>
      {IVI_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" }}>
          {s.title}
        </h3>
      </div>
      <div style={{ position: "absolute", bottom: isMobile ? 36 : 44, left: 0, right: 0, display: "flex", justifyContent: "center", gap: 10 }}>
        {IVI_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 IviDetail({ setScreen }) {
  const vw = useViewport();
  const isMobile = vw < 720;
  return (
    <>
      <IviCarousel />
      <PageIntro
        eyebrow="Ivi · Alexander Lotersztain, 2021"
        title="A stackable, customisable chair for diverse seating environments."
        body="A comfortable, sturdy and stackable seating solution designed to suit a wide range of environments. Available with or without armrests, across a range of bases, and customisable in finish, the collection is built to flex around the demands of each project — adapting to corporate, hospitality, civic and educational settings with equal ease."
        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/ivi/pillars/01.jpg",       alt: "Ivi · pressed-plywood seat in tan leather, castor base",     caption: "01 · Form" },
              { src: "images/collections/ivi/pillars/02.jpg", alt: "Ivi armchairs in burgundy and clay leather on castor bases", caption: "02 · Profile" },
              { src: "images/collections/ivi/pillars/03.jpg",            alt: "Ivi in American Oak veneer on a white four-leg base",        caption: "03 · Veneer" },
            ]}
            aspect="3/4"
          />
          <div style={{ alignSelf: "center" }}>
            <div style={{ fontSize: 11, letterSpacing: "0.16em", textTransform: "uppercase", color: "#6c6862", fontWeight: 500, marginBottom: 14 }}>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" }}>
              Reductive in form, considered in detail.
            </h2>
            <p style={{ fontSize: isMobile ? 15 : 16, lineHeight: 1.55, color: "#1a1917", maxWidth: "46ch", margin: 0, fontWeight: 500 }}>
              Ivi Chair is engineered to perform across daily use without imposing a strong stylistic point of view — making it a quietly versatile companion to a wide range of interiors.
            </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 Ivi 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: "Stackable", title: "Designed to stack for flexible, space-conscious use.",
              body: "Ivi is designed to stack efficiently, supporting flexible use across dynamic environments where seating layouts change frequently. The stackable design simplifies storage, transport and reconfiguration — making the collection well suited to event spaces, training rooms, dining environments and any setting where space is at a premium when chairs are not in use.",
              image: "images/collections/ivi/cover.jpg", alt: "Ivi · trio of forest-green shells, four-leg base" },
            { no: "02", kicker: "Bases & arms", title: "Configurable across armrests and base types.",
              body: "Ivi is offered in armless and armrest configurations, paired with a choice of standard four-leg or castor base — allowing the same chair to be specified across an extensive range of use cases. The four-leg variant supports stacking and dining environments; the castor variant delivers task-oriented mobility for workspaces and learning environments. Each variant shares the same considered form language, ensuring visual consistency when specified together.",
              image: "images/collections/ivi/hero/02.jpg", alt: "Ivi · castor-base armchairs around a round table" },
            { no: "03", kicker: "Finish", title: "Customisable across finish and material.",
              body: "Ivi is customisable across a range of finishes, allowing the collection to be tailored to the material and tonal intent of each project. Specifiers can configure seat finish — pressed-plywood veneer or COM/COL upholstery — and frame colour to suit the brief, from quietly recessive specifications for hospitality and civic settings, to more considered material combinations for corporate and educational interiors.",
              image: "images/collections/ivi/feature/02.jpg", alt: "Ivi · American Oak veneer shells, four-leg base" },
          ].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: "22ch" }}>
                {f.title}
              </h3>
              <p style={{ fontSize: 14, lineHeight: 1.6, color: "#6c6862", margin: 0, maxWidth: "38ch" }}>{f.body}</p>
            </div>
          ))}
        </div>
      </section>

      {/* Project in use */}
      <section style={{ padding: isMobile ? "64px 20px" : "120px max(24px, 3vw)", maxWidth: 1440, margin: "0 auto" }}>
        <div style={{ fontSize: 11, letterSpacing: "0.16em", textTransform: "uppercase", color: "#6c6862", fontWeight: 500, marginBottom: isMobile ? 24 : 32 }}>Project in use</div>
        <div
          onClick={() => setScreen && setScreen("project-canadian-academy")}
          role="link" tabIndex={0}
          onKeyDown={(e) => { if (e.key === "Enter" && setScreen) setScreen("project-canadian-academy"); }}
          style={{ display: "grid", gridTemplateColumns: isMobile ? "1fr" : "1.4fr 1fr", gap: isMobile ? 24 : 48, alignItems: "center", cursor: "pointer", maxWidth: 1100 }}>
          <div style={{ aspectRatio: "16/10", background: "#e4e2da", overflow: "hidden" }}>
            <img src="images/_legacy/collections/ivi-cafe-slat.jpg" alt="Ivi in American Oak at Canadian Academy, Kobe" loading="lazy"
              style={{ width: "100%", height: "100%", objectFit: "cover", objectPosition: "center 92%", display: "block" }} />
          </div>
          <div>
            <div style={{ display: "flex", justifyContent: "space-between", alignItems: "baseline", gap: 16, borderTop: "0.5px solid rgba(26,25,23,0.25)", paddingTop: 14 }}>
              <div style={{ fontFamily: "var(--font-display, Poppins, sans-serif)", fontSize: isMobile ? 22 : 26, color: "#1a1917", fontWeight: 500, letterSpacing: "-0.01em" }}>Canadian Academy</div>
              <div style={{ fontSize: 11, color: "#6c6862", letterSpacing: "0.12em", textTransform: "uppercase" }}>2022</div>
            </div>
            <div style={{ fontSize: 13, color: "#6c6862", marginTop: 8, letterSpacing: "0.02em" }}>Kobe, Japan</div>
            <div style={{ fontSize: 13, color: "#6c6862", marginTop: 4, letterSpacing: "0.02em" }}>Education</div>
            <p style={{ fontSize: isMobile ? 14 : 15, lineHeight: 1.6, color: "#1a1917", margin: "18px 0 0 0", maxWidth: "40ch" }}>
              A six-collection cross-section — including Ivi — specified across the Academy's renewed teaching and student commons in Kobe.
            </p>
            <div style={{ fontSize: 12, letterSpacing: "0.12em", textTransform: "uppercase", color: "#1a1917", fontWeight: 500, marginTop: 22, display: "inline-block", borderBottom: "0.5px solid #1a1917", paddingBottom: 4 }}>
              View project →
            </div>
          </div>
        </div>
      </section>

      <SpecificationSection
        skuImageBase="images/collections/ivi/skus"
        headline="Two SKUs. Standard leg or castor base."
        meta={[
          ["Design", "Alexander Lotersztain, 2021"],
          ["Sectors", "Corporate · Hospitality · Civic · Education"],
          ["Environment", "Indoor"],
          ["Warranty", "5 year structural"],
          ["Manufactured", "Australia"],
        ]}
        materials="Seat in pressed plywood with veneer, or upholstered in Customer's Own Material (COM) or Customer's Own Leather (COL). Frame in powder-coated mild steel. Standard seat height 450 mm."
        groups={[
          {
            label: "Standard leg · stackable",
            note: "Stackable. 550 mm width. Seat height 450 mm.",
            items: [
              { sku: "IVI-01", name: "Stackable chair · standard leg",    dims: "550 × 535 × 780H" },
            ],
          },
          {
            label: "Castor base · mobile",
            note: "Castor base for mobile use. 680 mm width. Seat height 450 mm.",
            items: [
              { sku: "IVI-05", name: "Chair · castor base",    dims: "680 × 535 × 780H" },
            ],
          },
        ]}
        extras={[
          {
            label: "Seat finish · upholstery",
            rows: [
              { text: "COM · Customer's Own Material" },
              { text: "COL · Customer's Own Leather" },
            ],
          },
          {
            label: "Seat finish · veneer",
            rows: [
              { text: "American Oak veneer" },
              { text: "Black-stained veneer" },
            ],
          },
          {
            label: "Frame finish · powder coat",
            rows: [
              { text: "White" },
              { text: "Black" },
              { text: "Custom · any colour available" },
            ],
          },
        ]}
        finishHeadline="Pressed-plywood seat in veneer or COM/COL upholstery; frame in white, black or custom powder coat."
      />

      <SpecifierDownloads collection="Ivi" />

      <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 => ["seed", "homework", "fit"].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="Ivi" />
    </>
  );
}

window.IviDetail = IviDetail;
