/* ============================================================
   CHARLES RICHARD AGHEDO — Collage Hero  (4 equal vertical strips)
   ============================================================
   No real product photography is available yet — each column
   falls back to the built-in text placeholder. Real photos/videos
   will be dropped in once assets are supplied.
   To swap imagery: update POSTERS / VIDEOS arrays below.
   ============================================================ */

const POSTERS = [
(window.RB_IMGS && window.RB_IMGS["TAILORING · MEN 01"]) || "",
(window.RB_IMGS && window.RB_IMGS["DRESSES · WOMEN 01"]) || "",
(window.RB_IMGS && window.RB_IMGS["OUTERWEAR · WOMEN 01"]) || "",
(window.RB_IMGS && window.RB_IMGS["TAILORING · WOMEN 01"]) || ""];

const VIDS = window.RB_VIDEOS || [];
const VIDEOS = [VIDS[0] || "", VIDS[1] || "", VIDS[2] || "", VIDS[3] || ""];
const EMB = window.RB_VIDEO_EMBEDS || [];
const EMBEDS = [EMB[0] || "", EMB[1] || "", EMB[2] || "", EMB[3] || ""];


const SLIDES = [
{
  eyebrow: "New Season · Menswear",
  h: ["Considered,", "Tailored."],
  cta: "Shop Menswear",
  ctaFn: (nav) => nav("shop", { gender: "Men" })
},
{
  eyebrow: "New Season · Womenswear",
  h: ["Dressed for", "The Moment."],
  cta: "Shop Womenswear",
  ctaFn: (nav) => nav("shop", { gender: "Women" })
},
{
  eyebrow: "The Season Edit",
  h: ["Show up.", "Show out."],
  cta: "Shop the Collection",
  ctaFn: (nav) => nav("shop", {})
}];


/* ── Single video strip (poster still behind an autoplay video) ── */
function ImageStrip({ src, videoSrc, embedSrc, delay, label }) {
  return (
    <div className="hcol-strip">
      {src ? (
        <img
          className="hcol-media hcol-poster"
          src={src}
          alt=""
          aria-hidden="true"
          style={{ animationDelay: delay + "ms", opacity: 1 }} />
      ) : (
        <div className="hcol-media hcol-poster" style={{ display: "grid", placeItems: "center", background: "color-mix(in oklab, var(--ink) 6%, var(--paper))" }}>
          <span className="mono" style={{ fontSize: 11, letterSpacing: "0.1em", color: "var(--ink-faint)", textTransform: "uppercase" }}>{label}</span>
        </div>
      )}
      {videoSrc ? (
        <video
          className="hcol-media"
          src={videoSrc}
          poster={src}
          autoPlay
          muted
          loop
          playsInline
          aria-hidden="true"
          style={{ animationDelay: delay + "ms" }} />
      ) : embedSrc ? (
        <iframe
          className="hcol-media"
          src={embedSrc}
          title={label}
          allow="autoplay; encrypted-media"
          allowFullScreen
          style={{ border: 0, zIndex: 1, animationDelay: delay + "ms" }} />
      ) : null}
    </div>);

}

/* ══════════════════════════════════════════════════════════
   MAIN COMPONENT
   ══════════════════════════════════════════════════════════ */
function HeroCollage({ onNav }) {
  const INTERVAL = 6000;

  const [idx, setIdx] = useState(0);
  const [textIn, setTextIn] = useState(true);

  useEffect(() => {
    const t = setInterval(() => {
      setTextIn(false);
      setTimeout(() => {
        setIdx((i) => (i + 1) % SLIDES.length);
        setTextIn(true);
      }, 450);
    }, INTERVAL);
    return () => clearInterval(t);
  }, []);

  const slide = SLIDES[idx];

  return (
    <section className="hero hcol-root" aria-label="Hero banner">

      {/* ── 4 equal vertical stock-image strips ── */}
      <div className="hcol-strips" aria-hidden="true">
        <ImageStrip src={POSTERS[0]} videoSrc={VIDEOS[0]} embedSrc={EMBEDS[0]} delay={0} label="Tailoring · Men" />
        <ImageStrip src={POSTERS[1]} videoSrc={VIDEOS[1]} embedSrc={EMBEDS[1]} delay={200} label="Dresses · Women" />
        <ImageStrip src={POSTERS[2]} videoSrc={VIDEOS[2]} embedSrc={EMBEDS[2]} delay={400} label="Outerwear · Women" />
        <ImageStrip src={POSTERS[3]} videoSrc={VIDEOS[3]} embedSrc={EMBEDS[3]} delay={600} label="Tailoring · Women" />
      </div>

      {/* Cinematic gradient overlay */}
      <div className="hcol-overlay" aria-hidden="true" style={EMBEDS.some(Boolean) ? { pointerEvents: "none" } : undefined} />

      {/* Gold top rule */}
      <div className="hcol-top-rule" aria-hidden="true" />

      {/* Vertical gap lines between strips */}
      <div className="hcol-dividers" aria-hidden="true">
        <span /><span /><span />
      </div>

      {/* Editorial text */}
      <div
        className={"hcol-content" + (textIn ? " hcol-content-in" : " hcol-content-out")}
        key={idx}>
        
        <p className="hcol-eyebrow mono">{slide.eyebrow}</p>
        <h1 className="display hcol-h">
          <span className="hcol-hline">{slide.h[0]}</span>
          <em className="hcol-hline hcol-hem">{slide.h[1]}</em>
        </h1>
        <div className="hcol-cta-row">
          <Btn onClick={() => slide.ctaFn(onNav)}>{slide.cta}</Btn>
          <Btn variant="ghost" arrow={false} className="on-dark"
          onClick={() => onNav("bespoke", {})}>
            Bespoke
          </Btn>
        </div>
      </div>



      {/* Bottom corner label */}
      <div className="hcol-corner mono" aria-hidden="true">
        {((window.BRAND && window.BRAND.name) || "Kaalon Luxury") + " · " + ((window.BRAND && window.BRAND.seasonTag) || "New Season")}
      </div>

      {/* Scroll pulse line */}
      <div className="hcol-scroll" aria-hidden="true">
        <span className="hcol-scroll-line" />
      </div>

    </section>);

}

Object.assign(window, { HeroCollage });