﻿// Hero — primeira dobra com nome do casal, data, contagem regressiva e CTA
window.Hero = function Hero() {
  const C = window.CONFIG;
  const t = window.useCountdown(C.dataEvento);
  const heroRef = React.useRef(null);
  const verseRef = React.useRef(null);

  React.useEffect(() => {
    const update = () => {
      if (!heroRef.current || !verseRef.current) return;
      const heroTop = heroRef.current.getBoundingClientRect().top + window.scrollY;
      const verseBottom = verseRef.current.getBoundingClientRect().bottom + window.scrollY;
      const h = verseBottom - heroTop - 56 + 32;
      heroRef.current.style.setProperty('--col-h', h + 'px');
    };
    update();
    window.addEventListener('resize', update);
    return () => window.removeEventListener('resize', update);
  }, []);

  return (
    <section id="hero" className="hero" ref={heroRef}>
      {/* Colunas laterais */}
      <img src="assets/coluna-esquerda.webp" className="hero-coluna hero-coluna--esq" aria-hidden="true" alt="" />
      <img src="assets/coluna-direita.webp"  className="hero-coluna hero-coluna--dir" aria-hidden="true" alt="" />

      {/* fundo com overlay e ornamentos de canto sutis */}
      {/*<div className="hero-bg" aria-hidden="true">
        <svg className="hero-corner hero-corner--tl" viewBox="0 0 200 200" preserveAspectRatio="none">
          <g fill="none" stroke="#ADADAD" strokeWidth="0.6" opacity="0.45">
            <path d="M0 60 Q40 40 60 0"/>
            <path d="M10 80 Q40 60 80 20"/>
            <path d="M20 20 Q30 30 50 25 Q60 22 70 30"/>
            <circle cx="55" cy="22" r="2.2" fill="#ADADAD"/>
            <circle cx="40" cy="40" r="1.2" fill="#ADADAD"/>
            <path d="M0 0 L0 18 M0 0 L18 0"/>
          </g>
        </svg>
        <svg className="hero-corner hero-corner--tr" viewBox="0 0 200 200" preserveAspectRatio="none">
          <g fill="none" stroke="#ADADAD" strokeWidth="0.6" opacity="0.45">
            <path d="M200 60 Q160 40 140 0"/>
            <path d="M190 80 Q160 60 120 20"/>
            <path d="M180 20 Q170 30 150 25 Q140 22 130 30"/>
            <circle cx="145" cy="22" r="2.2" fill="#ADADAD"/>
            <circle cx="160" cy="40" r="1.2" fill="#ADADAD"/>
            <path d="M200 0 L200 18 M200 0 L182 0"/>
          </g>
        </svg>
        <svg className="hero-corner hero-corner--bl" viewBox="0 0 200 200" preserveAspectRatio="none">
          <g fill="none" stroke="#ADADAD" strokeWidth="0.6" opacity="0.45">
            <path d="M0 140 Q40 160 60 200"/>
            <path d="M10 120 Q40 140 80 180"/>
            <path d="M20 180 Q30 170 50 175 Q60 178 70 170"/>
            <path d="M0 200 L0 182 M0 200 L18 200"/>
          </g>
        </svg>
        <svg className="hero-corner hero-corner--br" viewBox="0 0 200 200" preserveAspectRatio="none">
          <g fill="none" stroke="#ADADAD" strokeWidth="0.6" opacity="0.45">
            <path d="M200 140 Q160 160 140 200"/>
            <path d="M190 120 Q160 140 120 180"/>
            <path d="M200 200 L200 182 M200 200 L182 200"/>
          </g>
        </svg>
      </div>*/}

      {/* Brasão fixo no centro do arco — posição absoluta independe do conteúdo */}
      <div className="hero-crest">
        <img src="assets/brasao.png" alt="Brasão L&D" style={{ width: 180, height: 'auto' }} />
        <p className="hero-blessing">
          com as bênçãos <br/>de <strong>JEOVÁ</strong> e seus <strong>PAIS</strong>
        </p>
      </div>

      <div className="hero-inner">
        <img src="assets/nome-casal.webp" alt={`${C.noivo1} & ${C.noivo2}`} className="hero-names-img" />

        <p className="hero-invite">convidam para o seu casamento</p>

        <Ornament width={120} color="#711312" />

        <p className="hero-date">
          <span className="hero-date-part">11</span>
          <span className="hero-date-de">de</span>
          <span className="hero-date-part">JULHO</span>
          <span className="hero-date-de">de</span>
          <span className="hero-date-part hero-date-year">2026</span>
        </p>

        <p className="hero-date hero-time">
          <span className="hero-date-part">SÁBADO</span>
          <span className="hero-date-de">às</span>
          <span className="hero-date-part hero-date-year">19</span><span className="hero-date-part">H</span>
        </p>

        <div className="hero-venue">
          <p className="hero-venue-name">RESTAURANTE DIMATTONI</p>
          <p className="hero-venue-addr">ITABORAÍ, RIO DE JANEIRO</p>
        </div>

        <Ornament width={120} color="#711312" className="hero-ornament-bottom" />

        <p className="hero-verse" ref={verseRef}>
          "{C.versiculo}"
          <span className="hero-verse-ref">{C.versiculoRef}</span>
        </p>

        {/* Contagem regressiva */}
        {t.done ? (
          <div className="cd-grande-dia">Hoje é o grande dia!</div>
        ) : (
          <div className="cd-grid" aria-live="polite">
            <CountCard value={t.dias}     label="DIAS"  />
            <CountCard value={t.horas}    label="HORAS" />
            <CountCard value={t.minutos}  label="MIN"   />
            <CountCard value={t.segundos} label="SEG"   />
          </div>
        )}

        <div className="hero-cta">
          <a href="#presentes" className="btn-outline-gold">
            <Icon name="gift" size={14} /> Ver lista de presentes
          </a>
          <a href="#evento" className="hero-cta-text">
            Detalhes do evento <Icon name="chevron-down" size={14} />
          </a>
        </div>
      </div>


      <style>{`
        @font-face {
          font-family: 'Augustus';
          src: url('assets/fonts/AUGUSTUS.TTF') format('truetype');
          font-weight: normal;
          font-style: normal;
          font-display: swap;
        }
        @font-face {
          font-family: 'Didot';
          src: url('assets/fonts/Didot.otf') format('opentype');
          font-weight: normal;
          font-style: normal;
          font-display: swap;
        }
        @font-face {
          font-family: 'Didot';
          src: url('assets/fonts/Didot-Italic.otf') format('opentype');
          font-weight: 300;
          font-style: italic;
          font-display: swap;
        }
        @font-face {
          font-family: 'TrajanPro';
          src: url('assets/fonts/TrajanPro.ttf') format('truetype');
          font-weight: normal;
          font-style: normal;
          font-display: swap;
        }
        /* Colunas laterais */
        .hero-coluna {
          position: absolute;
          top: 56px;
          width: 48vw;
          max-width: 320px;
          height: var(--col-h, calc(100% - 56px));
          pointer-events: none;
          z-index: 0;
          object-fit: fill;
        }
        .hero-coluna--esq {
          right: 52%;
        }
        .hero-coluna--dir {
          left: 52%;
        }

        .hero {
          position: relative;
          min-height: 100vh;
          background:#ffffff;
          color: #ffffff;
          overflow: hidden;
          display: flex;
          align-items: center;
          justify-content: center;
          padding: 80px 24px 24px;
        }
        .hero-bg {
          position: absolute; inset: 0; pointer-events: none;
          background-image:
            radial-gradient(circle at 20% 30%, rgba(184,134,11,0.06), transparent 60%),
            radial-gradient(circle at 80% 70%, rgba(184,134,11,0.05), transparent 55%);
        }
        .hero-corner {
          position: absolute; width: 220px; height: 220px;
        }
        .hero-corner--tl { top: 56px; left: 0; }
        .hero-corner--tr { top: 56px; right: 0; }
        .hero-corner--bl { bottom: 0; left: 0; }
        .hero-corner--br { bottom: 0; right: 0; }

        .hero-inner {
          position: relative;
          z-index: 1;
          width: 100%;
          max-width: 720px;
          text-align: center;
          display: flex; flex-direction: column; align-items: center;
          padding-top: 220px;
        }
        .hero-eyebrow {
          font-family: 'Lato', sans-serif; font-weight: 300;
          font-size: 11px; letter-spacing: 6px;
          color: #F5C4B3; margin-bottom: 18px;
        }
        .hero-crest {
          position: absolute;
          top: 5%;
          left: 50%;
          transform: translateX(-50%);
          z-index: 2;
          pointer-events: none;
          display: flex;
          flex-direction: column;
          align-items: center;
          gap: 6px;
        }
        .hero-blessing {
          font-family: 'Augustus', 'Cormorant Garamond', serif;
          font-size: clamp(11px, 1.8vw, 15px);
          color: #000000;
          text-align: center;
          letter-spacing: 1.5px;
          line-height: 1.5;
          margin: 0;
          font-style: normal;
          white-space: nowrap;
          text-transform: uppercase;
        }
        .hero-blessing strong {
          font-size: clamp(14px, 2vw, 18px);
          font-weight: 700;
          letter-spacing: 2px;
        }
        .hero-invite {
          font-family: 'Augustus', 'Cormorant Garamond', serif;
          font-size: clamp(11px, 1.8vw, 15px);
          color: #000000;
          text-align: center;
          letter-spacing: 1.5px;
          line-height: 1.5;
          margin: 4px 0 20px;
          white-space: nowrap;
          text-transform: uppercase;
        }
        .hero-names {
          font-family: 'Pinyon Script', cursive;
          font-weight: 400;
          font-size: clamp(48px, 9vw, 88px);
          line-height: 1.0;
          color: #ffffff;
          margin: 4px 0 8px;
          text-shadow: 0 2px 0 rgba(0,0,0,0.18);
        }
        .hero-names-img {
          width: clamp(180px, 38vw, 340px);
          height: auto;
          margin: -8px 0 8px 0;
        }
        .hero-date {
          display: flex;
          align-items: baseline;
          gap: 10px;
          margin: 0;
        }
        .hero-date-part {
          font-family: 'Augustus', 'Cormorant Garamond', serif;
          font-size: clamp(16px, 2.2vw, 22px);
          font-weight: 700;
          color: #711312;
          letter-spacing: 2px;
        }
        .hero-date-de {
          font-family: 'Didot', 'Cormorant Garamond', serif;
          font-size: clamp(13px, 1.6vw, 17px);
          color: #711312;
          letter-spacing: 1px;
          font-style: italic;
          font-weight: 300;
        }
        .hero-date-year {
          font-family: 'TrajanPro', serif;
        }
        .hero-time {
          padding-top: 6px;
        }
        .hero-venue {
          display: flex;
          flex-direction: column;
          align-items: center;
          gap: 4px;
          margin: 4px 0 0;
        }
        .hero-venue-name {
          font-family: 'Augustus', serif;
          font-size: clamp(16px, 2.2vw, 22px);
          color: #000000;
          letter-spacing: 0.5px;
          margin: 0;
        }
        .hero-venue-addr {
          font-family: 'Augustus', serif;
          font-size: clamp(10px, 1.4vw, 13px);
          color: #000000;
          letter-spacing: 1.5px;
          margin: 0;
        }
        .hero-inner .ornament { margin: 4px 0; }
        .hero-inner .hero-ornament-bottom { margin-bottom: 20px; }
        .hero-verse {
          font-family: 'Cormorant Garamond', serif;
          font-style: italic;
          font-weight: 300;
          font-size: clamp(19px, 2vw, 22px);
          color: #000000; max-width: 460px;
          margin: 6px 0 4px; line-height: 1.55;
          white-space: pre-line;
        }
        .hero-verse-ref {
          display: block;
          font-family: 'Augustus', serif;
          font-size: clamp(11px, 1.4vw, 14px);
          font-style: normal;
          letter-spacing: 2px;
          color: #000000;
          margin-top: 8px;
          text-transform: uppercase;
        }

        .cd-grid {
          display: grid; grid-template-columns: repeat(4, 1fr);
          gap: 8px; margin: 44px 0 10px;
          width: 100%; max-width: 380px;
        }
        .cd-card {
          background: #711312;
          border: 0.5px solid #ADADAD;
          border-radius: 6px;
          padding: 8px 6px 6px;
          backdrop-filter: blur(2px);
        }
        .cd-number {
          font-family: 'Cormorant Garamond', serif;
          font-weight: 700; font-size: clamp(22px, 4vw, 32px);
          color: #ffffff; line-height: 1;
          font-variant-numeric: tabular-nums;
          display: inline-block;
          will-change: transform, opacity;
        }
        .cd-number.flip { animation: flipDown 0.55s ease both; }
        .cd-label {
          margin-top: 4px;
          font-family: 'Lato', sans-serif; font-size: 9px;
          letter-spacing: 3px; color: #ffffff; text-transform: uppercase;
        }
        .cd-grande-dia {
          font-family: 'Great Vibes', cursive;
          font-size: 36px; color: #ffffff; margin: 10px 0 14px;
        }

        .hero-cta {
          display: flex; flex-direction: column; align-items: center; gap: 8px;
          margin-top: 6px;
        }
        .hero-cta-text {
          font-family: 'Lato', sans-serif; font-size: 11px;
          letter-spacing: 3px; color: #711312; text-transform: uppercase;
          display: inline-flex; align-items: center; gap: 6px;
          padding: 6px 0;
          border-bottom: 1px solid rgba(245,196,179,0.35);
        }
        .hero-scroll {
          position: absolute; bottom: 22px; left: 50%;
          transform: translateX(-50%);
          color: #ADADAD;
          display: flex; flex-direction: column; align-items: center;
          animation: bounce 2.2s ease-in-out infinite;
          line-height: 0;
        }
        .hero-scroll svg + svg { margin-top: -14px; opacity: 0.65; }

        @media (max-width: 640px) {
          .hero { padding: 70px 18px 16px; }
          .hero-corner { width: 150px; height: 150px; }
          .hero-date { font-size: 15px; }
          .hero-verse { font-size: 14px; }
          .cd-grid { gap: 8px; }
          .cd-card { padding: 10px 4px; }
          .cd-label { font-size: 9px; letter-spacing: 2px; }
        }
      `}</style>
    </section>
  );
};

// Card individual da contagem regressiva — anima flipDown ao trocar valor
function CountCard({ value, label }) {
  const padded = String(value).padStart(2, '0');
  const [flipKey, setFlipKey] = React.useState(padded);
  React.useEffect(() => { setFlipKey(padded); }, [padded]);
  return (
    <div className="cd-card">
      <span key={flipKey} className="cd-number flip">{padded}</span>
      <div className="cd-label">{label}</div>
    </div>
  );
}



