// Hero / Landing — Nicholas & Shanthi
// Couple photo + floating typography + olive branches

const Hero = ({ scrollTo }) => {
  const [scrollY, setScrollY] = React.useState(0);

  React.useEffect(() => {
    const onScroll = () => setScrollY(window.scrollY);
    window.addEventListener('scroll', onScroll, { passive: true });
    return () => window.removeEventListener('scroll', onScroll);
  }, []);

  const parallax = Math.min(scrollY, 600);

  return (
    <section className="hero" id="hero">
      <div className="bg-orb bg-orb-1" />

      {/* Floating RSVP CTA — inline styles so layout holds even if hero.css is stale */}
      <button
        className="hero-rsvp-cta"
        onClick={() => scrollTo('rsvp')}
        style={{
          position: 'fixed',
          top: 'auto',
          right: 'auto',
          bottom: 28,
          left: 28,
          zIndex: 50,
          display: 'inline-flex',
          alignItems: 'center',
          gap: 12,
          padding: '14px 22px 14px 18px',
          borderRadius: 999,
          border: '1px solid var(--accent)',
          background: 'var(--accent)',
          color: 'var(--paper)',
          fontFamily: 'var(--sans)',
          cursor: 'pointer',
          boxShadow: '0 12px 28px -8px color-mix(in oklch, var(--accent) 50%, transparent)'
        }}>
        
        <span className="cta-dot" style={{ width: 8, height: 8, background: 'var(--paper)', borderRadius: '50%' }} />
        <span className="cta-label" style={{ fontFamily: 'var(--serif)', fontSize: 18, fontStyle: 'italic', letterSpacing: '0.02em' }}>RSVP</span>
        <span className="cta-sub mono" style={{ fontSize: 10, letterSpacing: '0.16em', opacity: 0.85, borderLeft: '1px solid rgba(255,255,255,0.3)', paddingLeft: 12 }}>by 15 · 06 · 2026</span>
        <span className="cta-arrow" style={{ fontSize: 14 }}>→</span>
      </button>

      <div className="hero-inner" style={{ transform: `translateY(${parallax * 0.1}px)`, textAlign: "center" }}>
        <div className="hero-meta">
          <div className="meta-line">
            <span className="dot" />
            <span>Ktima Panagiotopoulou</span>
            <span className="meta-sep">·</span>
            <span>Patras, Greece</span>
          </div>
          <div className="meta-line">
            <span>28 · 08 · 2026</span>
          </div>
        </div>

        <h1 className="hero-names" style={{ fontSize: 'clamp(72px, 11vw, 168px)', padding: "0px", margin: "2px 0px" }}>
          <span className="name-1">Nicholas</span>
          <span className="amp">&</span>
          <span className="name-2" style={{ margin: "0px", padding: "0px", borderStyle: "solid", borderWidth: "0px", height: "111px", width: "340px", fontSize: "122px" }}>Shanthi</span>
        </h1>

        <div className="hero-tagline">
          <span className="eyebrow">An Aegean Fusion</span>
          <p className="tagline-text">Three days of olive groves, vineyards and the Gulf of Patras, a quiet celebration of two families across four kitchens.


          </p>
        </div>

        <CouplePhotos />

        <div className="hero-bottom">
          <div className="countdown"><Countdown /></div>
          <button className="scroll-cue" onClick={() => scrollTo('plan')}>
            <span className="cue-label">Scroll to begin</span>
            <span className="cue-arrow">↓</span>
          </button>
          <div className="hero-rsvp-quick">
            <span className="eyebrow">By invitation</span>
            <span className="quick-meta">RSVP by 15 June 2026</span>
          </div>
        </div>
      </div>
    </section>);

};

const Countdown = () => {
  const [now, setNow] = React.useState(new Date());
  React.useEffect(() => {
    const t = setInterval(() => setNow(new Date()), 1000);
    return () => clearInterval(t);
  }, []);
  const target = new Date('2026-08-28T17:00:00');
  const diff = Math.max(0, target - now);
  const days = Math.floor(diff / (1000 * 60 * 60 * 24));
  const hrs = Math.floor(diff / (1000 * 60 * 60) % 24);
  const mins = Math.floor(diff / (1000 * 60) % 60);
  return (
    <div className="cd-row">
      <span className="eyebrow">Days until</span>
      <span className="cd-num">{days}</span>
      <span className="cd-sep">:</span>
      <span className="cd-num">{String(hrs).padStart(2, '0')}</span>
      <span className="cd-sep">:</span>
      <span className="cd-num">{String(mins).padStart(2, '0')}</span>
    </div>);

};

window.Hero = Hero;

const COUPLE_PICS = [
{ src: 'assets/couple-1.jpg', cap: 'Aboard the Patras ferry · Sept 2025' },
{ src: 'assets/couple-2.jpg', cap: 'A quiet evening in' },
{ src: 'assets/couple-3.jpg', cap: 'March 2025' },
{ src: 'assets/couple-4.jpg', cap: 'Summer 2024' }];


const CouplePhotos = () => {
  const [i, setI] = React.useState(0);
  React.useEffect(() => {
    const t = setInterval(() => setI((p) => (p + 1) % COUPLE_PICS.length), 4500);
    return () => clearInterval(t);
  }, []);
  return (
    <figure className="hero-photo" style={{
      position: 'relative', display: 'block', margin: '32px auto 0',
      maxWidth: 540, width: '100%', aspectRatio: '4/5'
    }}>
      {COUPLE_PICS.map((p, idx) =>
      <img
        key={p.src}
        src={p.src}
        alt="Nicholas and Shanthi"
        style={{
          position: 'absolute', inset: 0,
          width: '100%', height: '100%', objectFit: 'cover',
          opacity: idx === i ? 1 : 0,
          transition: 'opacity 1.2s ease',
          display: 'block'
        }} />

      )}
      <figcaption style={{ zIndex: 2 }}>
        <span className="mono">{COUPLE_PICS[i].cap}</span>
      </figcaption>
      <div style={{
        position: 'absolute', bottom: 18, right: 22, zIndex: 2,
        display: 'flex', gap: 6
      }}>
        {COUPLE_PICS.map((_, idx) =>
        <button
          key={idx}
          onClick={() => setI(idx)}
          aria-label={`Photo ${idx + 1}`}
          style={{
            width: idx === i ? 18 : 6, height: 6, padding: 0,
            borderRadius: 999, border: 'none', cursor: 'pointer',
            background: idx === i ? 'rgba(255,255,255,0.95)' : 'rgba(255,255,255,0.45)',
            transition: 'all 0.4s ease'
          }} />

        )}
      </div>
    </figure>);

};

window.CouplePhotos = CouplePhotos;