// ZION EventsRow — auto-rotating photo strip.
// Starts with the 2 stage shots (event-3 + event-4), then crossfades to the
// 2 fireball action shots (event-1 + event-2). 10s per slide, infinite loop.
// Same horizontal edge-blend + top/bottom mask as the hero.
function EventsRow({ onBook }) {
  const slides = [
    [
      { src: 'assets/event-3.jpg' },  // Red Bull stage — landscape
      { src: 'assets/event-4.jpg' },  // Bomboclat duo  — landscape
    ],
    [
      { src: 'assets/event-6.jpg' },  // hooded fire kick — landscape
      { src: 'assets/event-2.jpg' },  // fire bowl close-up — portrait (original)
    ],
  ];

  const [active, setActive] = React.useState(0);

  React.useEffect(() => {
    const t = setInterval(() => {
      setActive(a => (a + 1) % slides.length);
    }, 10000);
    return () => clearInterval(t);
  }, []);

  return (
    <section style={{
      color: '#fff', padding: '88px 0 56px', background: '#0A0A0A',
      position: 'relative', overflow: 'hidden',
    }}>
      <div style={{ maxWidth: 1280, margin: '0 auto', padding: '0 32px' }}>
        <h2 style={{
          fontFamily: "var(--font-script)", fontStyle: 'italic', textTransform: 'uppercase',
          fontSize: 'clamp(72px, 12vw, 180px)', lineHeight: 0.88, letterSpacing: '0.005em',
          margin: '0 0 12px', color: '#fff', textAlign: 'center',
        }}>EVENTS</h2>

        <p style={{
          fontFamily: 'Poppins', fontWeight: 500, fontSize: 'clamp(15px, 1.2vw, 17px)',
          color: 'rgba(255,255,255,0.72)', textAlign: 'center',
          maxWidth: 520, margin: '0 auto 28px', lineHeight: 1.55,
        }}>
          Festivals, brand activations, content shoots. Bring the fireball to your stage.
        </p>

        <div style={{ display: 'flex', justifyContent: 'center', marginBottom: 56 }}>
          <BookNowButton onClick={onBook} />
        </div>
      </div>

      {/* Full-width blended strip. Each slide is absolutely stacked and
          cross-fades via opacity, so the mask/fade reads identically across slides. */}
      <div style={{
        position: 'relative', width: '100%',
        height: 'clamp(360px, 42vw, 580px)',
        WebkitMaskImage: 'linear-gradient(180deg, transparent 0%, #000 14%, #000 86%, transparent 100%)',
        maskImage: 'linear-gradient(180deg, transparent 0%, #000 14%, #000 86%, transparent 100%)',
      }}>
        {slides.map((photos, idx) => (
          <div key={idx} style={{
            position: 'absolute', inset: 0,
            display: 'flex', alignItems: 'stretch', gap: 0,
            opacity: idx === active ? 1 : 0,
            transition: 'opacity 1200ms cubic-bezier(0.16,1,0.3,1)',
            pointerEvents: idx === active ? 'auto' : 'none',
          }}>
            {photos.map((p, i) => (
              <EventPhoto key={p.src} src={p.src} overlapLeft={i > 0} />
            ))}
          </div>
        ))}
      </div>

      {/* Tiny rotation indicator (dots) */}
      <div style={{
        display: 'flex', justifyContent: 'center', gap: 8,
        marginTop: 28,
      }}>
        {slides.map((_, idx) => (
          <button key={idx}
            onClick={() => setActive(idx)}
            aria-label={`Show slide ${idx + 1}`}
            style={{
              width: idx === active ? 28 : 8, height: 8, borderRadius: 999,
              background: idx === active ? '#F7591F' : 'rgba(255,255,255,0.3)',
              border: 'none', cursor: 'pointer', padding: 0,
              transition: 'width 320ms cubic-bezier(0.16,1,0.3,1), background 220ms',
            }}
          />
        ))}
      </div>
    </section>
  );
}

// Single event photo with horizontal edge-fade so neighbors bleed into each other.
function EventPhoto({ src, overlapLeft }) {
  const m = 'linear-gradient(90deg, transparent 0%, #000 14%, #000 86%, transparent 100%)';
  return (
    <div style={{
      flex: 1, height: '100%', position: 'relative', overflow: 'hidden',
      WebkitMaskImage: m, maskImage: m,
      marginLeft: overlapLeft ? '-9%' : 0,
    }}>
      <img src={src} alt="" style={{
        width: '100%', height: '100%', objectFit: 'cover', display: 'block',
      }} />
    </div>
  );
}

// BookNowButton — rounded pill CTA. Same family as the hero PillButton but
// scoped to events so it can be tweaked independently.
function BookNowButton({ onClick }) {
  const [hover, setHover] = React.useState(false);
  const [press, setPress] = React.useState(false);
  return (
    <button onClick={onClick}
      onMouseEnter={() => setHover(true)}
      onMouseLeave={() => { setHover(false); setPress(false); }}
      onMouseDown={() => setPress(true)}
      onMouseUp={() => setPress(false)}
      style={{
        fontFamily: 'Poppins, sans-serif', fontWeight: 800,
        fontSize: 14, letterSpacing: '0.14em',
        textTransform: 'uppercase',
        background: hover ? '#C8420E' : '#F7591F', color: '#fff',
        border: 'none', borderRadius: 999,
        padding: '18px 48px', cursor: 'pointer',
        boxShadow: hover
          ? '0 0 24px rgba(247,89,31,0.55), 0 8px 28px rgba(247,89,31,0.35)'
          : '0 8px 28px rgba(247,89,31,0.35)',
        transform: press ? 'scale(0.985)' : 'scale(1)',
        transition: 'transform 120ms cubic-bezier(0.7,0,0.2,1), background 140ms, box-shadow 200ms',
        display: 'inline-flex', alignItems: 'center', gap: 10,
      }}>
      Book Now
      <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.5" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true">
        <path d="M7 17 L17 7" />
        <path d="M8 7 H17 V16" />
      </svg>
    </button>
  );
}

window.EventsRow = EventsRow;
