// 3 variações do Hero, escolhíveis via Tweaks

function Hero({ variant = 'editorial' }) {
  if (variant === 'gradient') return <HeroGradient />;
  if (variant === 'showcase') return <HeroShowcase />;
  return <HeroEditorial />;
}

// VARIANT 1: Editorial split (collage à esquerda, headline/CTA à direita)
function HeroEditorial() {
  const [choker, setChoker] = React.useState(null);
  // Lê config do admin. Quando mode='custom', usa overrides em vez do choker aleatório.
  const heroCfg = (typeof window !== 'undefined' && window.SITE_CONFIG?.hero) || null;
  const customMode = heroCfg?.mode === 'custom';

  React.useEffect(() => {
    if (customMode) return; // não busca produto quando custom
    fetch('/api/products?cat=Chokers')
      .then(r => r.ok ? r.json() : null)
      .then(data => {
        const list = data?.products || [];
        if (list.length) setChoker(list[Math.floor(Math.random() * list.length)]);
      })
      .catch(() => {});
  }, [customMode]);

  const imgs = (choker?.images || []).map(i => i.url).filter(Boolean);
  const big = customMode
    ? (heroCfg.image || null)
    : (imgs[0] || choker?.image || null);
  const small = customMode
    ? (heroCfg.image_2 || heroCfg.image || null)
    : (imgs[1] || big);
  const href = customMode
    ? (heroCfg.badge_link || 'categoria.html')
    : (choker?.slug ? `/produto?slug=${choker.slug}` : 'categoria.html');
  const badgeText = customMode
    ? (heroCfg.badge_text || null)
    : (choker?.name ? 'Em destaque · ' + choker.name : null);
  const imageAlt = customMode
    ? (heroCfg.image_alt || 'Destaque Lua Azul')
    : (choker?.name || 'Choker em destaque');
  const eyebrowText = (customMode && heroCfg.eyebrow) || 'Coleção 2026 · Atelier Lua Azul';
  const headlineTop    = (customMode && heroCfg.headline_top)    || 'Joia que';
  const headlineEm     = (customMode && heroCfg.headline_em)     || 'te conhece';
  const headlineBottom = (customMode && heroCfg.headline_bottom) || 'antes do espelho.';

  return (
    <section id="top" className="hero-editorial" style={{
      background: 'radial-gradient(ellipse at top, #f7fdfe 0%, white 60%)',
      padding: 'clamp(36px, 6vw, 72px) 0 clamp(56px, 8vw, 96px)',
      position: 'relative', overflow: 'hidden',
    }}>
      {/* glow dourado sutil canto direito */}
      <div aria-hidden="true" style={{
        position: 'absolute', top: '-40%', right: '-15%',
        width: 'min(720px, 80vw)', height: 'min(720px, 80vw)', borderRadius: '50%',
        background: 'radial-gradient(circle, rgba(212,175,106,0.12) 0%, transparent 60%)',
        filter: 'blur(20px)', pointerEvents: 'none',
      }}/>
      <div aria-hidden="true" style={{
        position: 'absolute', bottom: '-30%', left: '-10%',
        width: 'min(620px, 70vw)', height: 'min(620px, 70vw)', borderRadius: '50%',
        background: 'radial-gradient(circle, rgba(6,182,212,0.10) 0%, transparent 60%)',
        filter: 'blur(20px)', pointerEvents: 'none',
      }}/>

      <div className="container hero-grid" style={{
        position: 'relative', zIndex: 1,
        display: 'grid', gridTemplateColumns: '1.05fr 1fr',
        gap: 'clamp(40px, 6vw, 80px)', alignItems: 'center',
      }}>
        {/* Left: visual collage */}
        <div className="hero-collage reveal" style={{ position: 'relative', aspectRatio: '5/6' }}>
          <a href={href} style={{
            position: 'absolute', inset: '0 50px 50px 0',
            borderRadius: 28, overflow: 'hidden',
            boxShadow: '0 40px 80px -28px rgba(8,51,68,0.32)',
            display: 'block', background: '#f6f2ec',
            transition: 'transform .5s cubic-bezier(.2,.7,.2,1)',
          }}
          onMouseEnter={(e)=> e.currentTarget.style.transform = 'translate(-4px, -4px)'}
          onMouseLeave={(e)=> e.currentTarget.style.transform = 'none'}>
            {big
              ? <img src={big} alt={imageAlt} fetchpriority="high" decoding="async" style={{ width: '100%', height: '100%', objectFit: 'cover', display: 'block' }}/>
              : <JewelArt cat="Chokers" hue={185} tone="deep" />}
          </a>
          <a href={href} style={{
            position: 'absolute', bottom: 0, right: 0,
            width: '52%', aspectRatio: '4/5',
            borderRadius: 22, overflow: 'hidden',
            border: '6px solid white',
            boxShadow: '0 24px 56px -12px rgba(8,51,68,0.35)',
            animation: 'float-y 7s ease-in-out infinite',
            display: 'block', background: '#f6f2ec',
          }}>
            {small
              ? <img src={small} alt="" loading="lazy" decoding="async" style={{ width: '100%', height: '100%', objectFit: 'cover', display: 'block' }}/>
              : <JewelArt cat="Chokers" hue={178} tone="soft" />}
          </a>
          {/* Badge dourado */}
          {badgeText && (
            <div className="hero-badge" style={{
              position: 'absolute', top: 24, left: 24,
              background: 'white', borderRadius: 999,
              padding: '10px 16px', fontSize: 11, fontWeight: 600,
              fontFamily: 'var(--mono)', letterSpacing: '0.14em', textTransform: 'uppercase',
              color: 'var(--gold-deep)',
              display: 'inline-flex', alignItems: 'center', gap: 8,
              boxShadow: '0 8px 24px -8px rgba(8,51,68,0.18)',
              border: '1px solid rgba(212,175,106,0.3)',
            }}>
              <span style={{ width: 6, height: 6, borderRadius: '50%', background: 'var(--gold)' }}/>
              {badgeText}
            </div>
          )}
        </div>

        {/* Right: copy editorial + CTA premium */}
        <div className="hero-copy reveal" style={{ position: 'relative' }}>
          <div className="eyebrow hero-eyebrow" style={{ color: 'var(--gold-deep)' }}>
            <span style={{ display:'inline-block', width:20, height:1, background:'currentColor', verticalAlign:'middle', marginRight:8 }}/>
            {eyebrowText}
          </div>
          <h1 className="serif hero-title" style={{
            fontSize: 'clamp(40px, 6vw, 84px)', lineHeight: 1.02,
            margin: '18px 0 22px', fontWeight: 400, letterSpacing: '-0.025em',
            color: 'var(--ink)', textWrap: 'balance',
          }}>
            {headlineTop}{headlineTop ? ' ' : ''}<em style={{
              fontStyle: 'italic',
              background: 'var(--grad-gold)',
              WebkitBackgroundClip: 'text', WebkitTextFillColor: 'transparent',
              backgroundClip: 'text',
            }}>{headlineEm}</em>{headlineBottom ? <><br/>{headlineBottom}</> : null}
          </h1>
          <p className="hero-lede" style={{
            fontSize: 'clamp(15px, 1.2vw, 18px)', lineHeight: 1.65, color: 'var(--ink-2)',
            margin: '0 0 32px', maxWidth: 480, textWrap: 'pretty',
          }}>
            {(customMode && heroCfg.lede)
              ? heroCfg.lede
              : 'Peças feitas à mão em Salvador, com banho de ouro 18k e aço inox legítimo. Pequenos lotes, atenção em cada acabamento, joia pra durar mais que a estação.'}
          </p>
          <div style={{ display: 'flex', gap: 14, flexWrap: 'wrap', marginBottom: 36 }}>
            <a href="categoria.html" className="btn btn-primary hero-cta-primary silver-shimmer" style={{
              height: 56, padding: '0 28px', fontSize: 15,
              background: 'var(--grad-navy)',
              boxShadow: '0 14px 36px -10px rgba(10,31,61,0.55)',
              borderRadius: 999, fontWeight: 600, letterSpacing: '0.02em',
              textDecoration: 'none',
              display: 'inline-flex', alignItems: 'center', gap: 10,
              transition: 'transform .25s ease, box-shadow .25s ease',
            }}
            onMouseEnter={(e)=>{ e.currentTarget.style.transform = 'translateY(-2px) scale(1.02)'; e.currentTarget.style.boxShadow = '0 20px 44px -10px rgba(10,31,61,0.65)'; }}
            onMouseLeave={(e)=>{ e.currentTarget.style.transform = 'none'; e.currentTarget.style.boxShadow = '0 14px 36px -10px rgba(10,31,61,0.55)'; }}>
              Explorar coleção
              <svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round"><path d="M5 12h14M13 6l6 6-6 6"/></svg>
            </a>
            <a href="sobre.html" className="btn btn-ghost hero-cta-ghost" style={{
              height: 56, padding: '0 24px', fontSize: 14,
              borderRadius: 999, fontWeight: 500,
              textDecoration: 'none', color: 'var(--ink)',
              background: 'white', border: '1px solid var(--silver)',
              display: 'inline-flex', alignItems: 'center', gap: 8,
              transition: 'border-color .2s ease, background .2s ease',
            }}
            onMouseEnter={(e)=>{ e.currentTarget.style.borderColor = 'var(--gold)'; e.currentTarget.style.background = '#fffaf0'; }}
            onMouseLeave={(e)=>{ e.currentTarget.style.borderColor = 'var(--silver)'; e.currentTarget.style.background = 'white'; }}>
              Nossa história
            </a>
          </div>

          {/* trust strip */}
          <div style={{
            display: 'flex', flexWrap: 'wrap',
            gap: '20px 40px', paddingTop: 28,
            borderTop: '1px solid var(--line)',
          }}>
            <Trust v="14 etapas" l="feito à mão"/>
            <Trust v="Ouro 18k" l="banho premium"/>
            <Trust v="90 dias" l="de garantia"/>
            <Trust v="Salvador" l="Bahia · 2025"/>
          </div>
        </div>
      </div>
    </section>
  );
}

function Trust({ v, l }) {
  return (
    <div>
      <div className="serif" style={{ fontSize: 30, fontWeight: 500, color: 'var(--blue-700)', lineHeight: 1 }}>{v}</div>
      <div style={{ fontSize: 12, color: 'var(--ink-3)', marginTop: 4, fontFamily: 'var(--mono)', textTransform: 'uppercase', letterSpacing: '0.08em' }}>{l}</div>
    </div>
  );
}

// VARIANT 2: Full-bleed gradient with floating product
function HeroGradient() {
  return (
    <section id="top" style={{
      position: 'relative', overflow: 'hidden',
      background: 'linear-gradient(135deg, #0e7490 0%, #0891b2 50%, #06b6d4 100%)',
      color: 'white',
      minHeight: 'min(820px, 90vh)',
      padding: '40px 0 80px',
      display: 'flex', alignItems: 'center',
    }}>
      {/* ambient orbs */}
      <div style={{
        position: 'absolute', top: '-10%', left: '-5%',
        width: 520, height: 520, borderRadius: '50%',
        background: 'radial-gradient(circle, rgba(103,232,249,0.45), transparent 60%)',
        filter: 'blur(20px)',
      }}/>
      <div style={{
        position: 'absolute', bottom: '-15%', right: '-8%',
        width: 620, height: 620, borderRadius: '50%',
        background: 'radial-gradient(circle, rgba(20,184,166,0.55), transparent 60%)',
        filter: 'blur(30px)',
      }}/>
      {/* sparkles */}
      {Array.from({length: 30}).map((_,i)=>(
        <span key={i} style={{
          position: 'absolute',
          left: `${(i*37) % 100}%`, top: `${(i*53) % 100}%`,
          width: 2 + (i%3), height: 2 + (i%3),
          background: 'white', borderRadius: '50%',
          opacity: 0.3 + (i%3)*0.2,
          boxShadow: '0 0 8px rgba(255,255,255,0.7)',
        }}/>
      ))}

      <div className="container" style={{ position: 'relative', display: 'grid', gridTemplateColumns: '1.1fr 1fr', alignItems: 'center', gap: 60 }} className="hero-grid">
        <div className="reveal">
          <div className="eyebrow" style={{ color: 'rgba(165,243,252,0.95)' }}>NOVA COLEÇÃO · LUA AZUL 26</div>
          <h1 className="serif" style={{
            fontSize: 'clamp(52px, 6vw, 96px)', lineHeight: 0.96,
            margin: '20px 0 0', fontWeight: 400, letterSpacing: '-0.02em',
          }}>
            Joias que<br/>
            brilham <em style={{
              fontStyle: 'italic',
              background: 'linear-gradient(135deg, #a5f3fc, #ffffff)',
              WebkitBackgroundClip: 'text', WebkitTextFillColor: 'transparent',
            }}>como o céu</em><br/>
            antes da chuva.
          </h1>
          <p style={{
            fontSize: 17, color: 'rgba(255,255,255,0.82)', lineHeight: 1.65,
            margin: '32px 0 40px', maxWidth: 500,
          }}>
            Brincos, colares, pulseiras e chokers banhados a ouro 18k ou em Aço Inox Legitimo. Feitos à mão em Salvador, Bahia. Frete por transportadora em todo o Brasil.
          </p>
          <div style={{ display: 'flex', gap: 12, flexWrap: 'wrap' }}>
            <a href="#produtos" className="btn" style={{
              height: 56, padding: '0 30px', fontSize: 15,
              background: 'white', color: 'var(--blue-800)',
              boxShadow: '0 16px 40px -8px rgba(0,0,0,0.35)',
            }}>
              Comprar agora <Icon name="arrow" size={16}/>
            </a>
            <a href="#produtos" className="btn" style={{
              height: 56, padding: '0 28px', fontSize: 15,
              background: 'rgba(255,255,255,0.12)', color: 'white',
              border: '1px solid rgba(255,255,255,0.25)',
              backdropFilter: 'blur(8px)',
            }}>
              Ver tudo
            </a>
          </div>

          <div style={{ display: 'flex', gap: 32, marginTop: 56, color: 'rgba(255,255,255,0.8)', fontSize: 12, fontFamily: 'var(--mono)', textTransform: 'uppercase', letterSpacing: '0.1em' }}>
            <span style={{ display: 'flex', alignItems: 'center', gap: 8 }}><Icon name="shield" size={14}/> Garantia 90 dias</span>
            <span style={{ display: 'flex', alignItems: 'center', gap: 8 }}><Icon name="truck" size={14}/> Envio Brasil</span>
            <span style={{ display: 'flex', alignItems: 'center', gap: 8 }}><Icon name="sparkle" size={14}/> Feito à mão</span>
          </div>
        </div>

        <div style={{ position: 'relative', aspectRatio: '4/5' }}>
          <div style={{
            position: 'absolute', inset: 0,
            borderRadius: 24, overflow: 'hidden',
            border: '8px solid rgba(255,255,255,0.18)',
            boxShadow: '0 40px 80px -20px rgba(0,0,0,0.45)',
            animation: 'float-y 8s ease-in-out infinite',
          }}>
            <JewelArt cat="Colares" hue={182} tone="deep"/>
          </div>
          {/* price chip */}
          <div style={{
            position: 'absolute', bottom: -20, left: -20,
            background: 'white', color: 'var(--ink)',
            padding: '16px 20px', borderRadius: 20,
            boxShadow: '0 20px 40px -10px rgba(0,0,0,0.25)',
          }}>
            <div style={{ fontSize: 10, fontFamily: 'var(--mono)', color: 'var(--ink-3)', letterSpacing: '0.1em', textTransform: 'uppercase' }}>Colar Gota Celeste</div>
            <div className="serif" style={{ fontSize: 28, marginTop: 4 }}>R$ 419<span style={{ fontSize: 13, color: 'var(--ink-3)' }}> ou 6x R$ 69,83</span></div>
          </div>
        </div>
      </div>
    </section>
  );
}

// VARIANT 3: Showcase grid (3 columns of imagery + centered copy on top)
function HeroShowcase() {
  return (
    <section id="top" style={{
      background: 'linear-gradient(180deg, #f0f9ff 0%, #ffffff 100%)',
      padding: '60px 0 80px', position: 'relative', overflow: 'hidden',
    }}>
      <div className="container">
        <div className="reveal" style={{ textAlign: 'center', maxWidth: 820, margin: '0 auto 56px' }}>
          <div className="eyebrow" style={{ marginBottom: 18 }}>· Lua Azul · joias autorais ·</div>
          <h1 className="serif" style={{
            fontSize: 'clamp(56px, 6.5vw, 104px)', lineHeight: 0.96,
            margin: 0, fontWeight: 400, letterSpacing: '-0.025em',
          }}>
            Para mulheres que<br/>
            carregam o <em style={{
              fontStyle: 'italic',
              background: 'var(--grad)',
              WebkitBackgroundClip: 'text', WebkitTextFillColor: 'transparent',
            }}>oceano</em> consigo.
          </h1>
          <p style={{ fontSize: 18, color: 'var(--ink-2)', lineHeight: 1.55, margin: '24px auto 32px', maxWidth: 580 }}>
            Brincos, colares, pulseiras e chokers banhados a ouro 18k ou em Aço Inox Legitimo. Feitos à mão em Salvador, Bahia.
          </p>
          <div style={{ display: 'flex', gap: 12, justifyContent: 'center', flexWrap: 'wrap' }}>
            <a href="#produtos" className="btn btn-primary" style={{ height: 54, padding: '0 28px', fontSize: 15 }}>
              Comprar agora <Icon name="arrow" size={16}/>
            </a>
            <a href="#produtos" className="btn btn-ghost" style={{ height: 54, padding: '0 24px', fontSize: 15 }}>
              Ver tudo
            </a>
          </div>
        </div>

        {/* 3-up image grid */}
        <div style={{
          display: 'grid', gridTemplateColumns: '1fr 1.2fr 1fr',
          gap: 20, alignItems: 'end',
          maxWidth: 1100, margin: '0 auto',
        }} className="hero-3up">
          {[
            { cat: 'Brincos', hue: 180, h: 360, off: 40 },
            { cat: 'Colares', hue: 190, h: 460, off: 0 },
            { cat: 'Pulseiras', hue: 175, h: 380, off: 60 },
          ].map((it,i)=>(
            <div key={i} style={{
              aspectRatio: 'auto', height: it.h,
              borderRadius: 20, overflow: 'hidden',
              boxShadow: '0 30px 60px -20px rgba(8,51,68,0.25)',
              transform: `translateY(${it.off}px)`,
              animation: `float-y ${6 + i}s ease-in-out infinite`,
              animationDelay: `${i*0.4}s`,
            }}>
              <JewelArt cat={it.cat} hue={it.hue} tone={i===1 ? 'deep' : 'soft'}/>
            </div>
          ))}
        </div>
      </div>
    </section>
  );
}

Object.assign(window, { Hero });
