/* Hero plein écran avec image, titre — données chargées depuis Firebase */
function Hero({ onCta, onSecondary }) {
  const [content, setContent] = React.useState(null);
  const [H, setH] = React.useState({});
  React.useEffect(() => { BrionServices.getHeaders().then(h => setH(h.hero || {})); }, []);

  React.useEffect(() => {
    BrionServices.getContent()
      .then(setContent)
      .catch(() => setContent({}));
  }, []);

  const blocks = content?.blocks || [
    { type: 'title',    text: content?.hero_title    || 'La Ferme Fortifiée de Brion' },
    { type: 'subtitle', text: content?.hero_subtitle || "Au sein d'un corps de ferme fortifié, à Croutoy — entre Compiègne et Soissons, à 80 km de Paris." },
  ];

  const bgImage = content?.imageUrl || '/ui_kits/public_site/assets/photo-cour-soir.webp';

  return (
    <section id="hero" style={{
      position:'relative', minHeight:'92vh', display:'flex', alignItems:'flex-end',
      backgroundImage:`url('${bgImage}')`,
      backgroundSize:'cover', backgroundPosition:'center',
      color:'var(--cream-100)',
    }}>
      <div className="container" style={{position:'relative',zIndex:2,paddingBottom:'var(--space-10)',paddingTop:'var(--space-10)'}}>
        <span className="eyebrow" style={{color:'var(--gold-200)'}}>{H.eyebrow || 'Mariages · Séminaires · Événements'}</span>
        <hr className="rule-gold" style={{background:'var(--gold-200)',margin:'12px 0 24px'}} />
        {blocks.map((block, i) => (
          block.type === 'title'
            ? <h1 key={i} className="hero" style={{color:'var(--cream-50)',maxWidth:'14ch',margin:'0 0 18px',fontSize:'clamp(2.75rem, 7vw, 5.5rem)',lineHeight:1.05}}>
                {String(block.text).split(/(\s+)/).map((w, j) => /^de$/i.test(w) ? <span key={j} className="hero-de">{w}</span> : w)}
              </h1>
            : <p key={i} className="lede" style={{color:'var(--cream-100)',maxWidth:'52ch',margin:'0 0 18px',fontSize:20,lineHeight:1.6,opacity:0.92}}>{block.text}</p>
        ))}
        <div style={{display:'flex',gap:14,flexWrap:'wrap',marginTop:14}}>
          <button className="btn btn-gold" onClick={onCta}>Demander un devis</button>
          <button className="btn btn-ghost-light" onClick={onSecondary}>Visiter le domaine</button>
        </div>
      </div>
    </section>
  );
}
window.Hero = Hero;
