/* ============================================================
   lookslikeagoodman — Collage Hero (4 equal vertical strips)
   Real brand stills as the full-colour poster layer; real brand
   footage (uploaded, local — never hotlinked) plays on top.
   ============================================================ */

const POSTERS = [
(window.RB_IMGS && window.RB_IMGS["AGBADA · TRADITIONAL"]) || "",
(window.RB_IMGS && window.RB_IMGS["KAFTAN · SIGNATURE"]) || "",
(window.RB_IMGS && window.RB_IMGS["SETS · CONTEMPORARY"]) || "",
(window.RB_IMGS && window.RB_IMGS["OCCASION · FAMILY"]) || ""];

const VIDS = (window.RB_VIDEOS && window.RB_VIDEOS.length) ? window.RB_VIDEOS : [];
const VIDEOS = [VIDS[0] || "", VIDS[1] || "", VIDS[2] || "", VIDS[3] || ""];

const SLIDES = [
{ eyebrow: "lookslikeagoodman", h: ["Looks like", "a good man."], cta: "Shop the Edit", ctaFn: (nav) => nav("shop", {}) },
{ eyebrow: "Signature Kaftans", h: ["Cut with", "purpose."], cta: "Shop Kaftans", ctaFn: (nav) => nav("shop", { cat: "Kaftan" }) },
{ eyebrow: "Occasion & Family", h: ["Dressed as", "one."], cta: "Shop Occasion", ctaFn: (nav) => nav("shop", { cat: "Occasion" }) }];

function ImageStrip({ src, video, delay }) {
  return (
    <div className="hcol-strip">
      <img className="hcol-media hcol-poster" src={src} alt="" aria-hidden="true" style={{ animationDelay: delay + "ms", opacity: 1 }} />
      {video && (
        <video
          className="hcol-media"
          src={video}
          poster={src}
          autoPlay muted loop playsInline preload="auto"
          aria-hidden="true"
          style={{ animationDelay: delay + "ms" }}
        />
      )}
    </div>
  );
}

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">
      <div className="hcol-strips" aria-hidden="true">
        <ImageStrip src={POSTERS[0]} video={VIDEOS[0]} delay={0} />
        <ImageStrip src={POSTERS[1]} video={VIDEOS[1]} delay={200} />
        <ImageStrip src={POSTERS[2]} video={VIDEOS[2]} delay={400} />
        <ImageStrip src={POSTERS[3]} video={VIDEOS[3]} delay={600} />
      </div>
      <div className="hcol-overlay" aria-hidden="true" />
      <div className="hcol-top-rule" aria-hidden="true" />
      <div className="hcol-dividers" aria-hidden="true"><span /><span /><span /></div>
      <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("custom", {})}>Enquire</Btn>
        </div>
      </div>
      <div className="hcol-corner mono" aria-hidden="true">
        {(window.BRAND && window.BRAND.igHandle) || "@lookslikeagoodman"}
      </div>
      <div className="hcol-scroll" aria-hidden="true"><span className="hcol-scroll-line" /></div>
    </section>
  );
}

Object.assign(window, { HeroCollage });
