/* Vocations — trois usages du domaine — données chargées depuis Firebase */
function VocationsSection({ onRequest }) {
  const [data, setData] = React.useState(null);

  React.useEffect(() => {
    BrionServices.getVocations()
      .then(setData)
      .catch(() => setData(null));
  }, []);

  if (!data) {
    return (
      <section id="vocations" className="section reveal">
        <div className="container" style={{textAlign:'center',padding:'var(--space-10) 0',color:'var(--gold-700)',fontFamily:'var(--font-display)',fontSize:16}}>
          Chargement…
        </div>
      </section>
    );
  }

  const header   = data.header || {};
  const vocations = data.items  || [];

  return (
    <section id="vocations" className="section reveal">
      <div className="container">
        <div className="section-head">
          <span className="eyebrow">{header.eyebrow || 'Trois vocations'}</span>
          <hr className="rule-gold rule-gold--center" />
          <h2>{header.title || 'Un même lieu, plusieurs usages'}</h2>
          <p className="lede">{header.lede || ''}</p>
        </div>

        <div style={{display:'flex',flexDirection:'column',gap:'var(--space-7)'}}>
          {vocations.map((v, i) => {
            const reverse = i % 2 === 1;
            return (
              <div key={v.key} className="grid-2col" style={{direction: reverse ? 'rtl' : 'ltr'}}>
                <div style={{direction:'ltr'}}>
                  <span className="eyebrow">{v.eyebrow}</span>
                  <hr className="rule-gold" />
                  <h3 style={{margin:'0 0 14px',fontFamily:'var(--font-display)',fontWeight:500}}>{v.title}</h3>
                  <p style={{fontSize:16,lineHeight:1.7,color:'var(--stone-200)',margin:'0 0 18px'}}>{v.body}</p>
                  <ul style={{listStyle:'none',padding:0,margin:'0 0 22px',display:'grid',gridTemplateColumns:'1fr 1fr',gap:8}}>
                    {(v.bullets || []).map(b => (
                      <li key={b} style={{display:'flex',gap:8,fontSize:14,color:'var(--stone-200)',lineHeight:1.5}}>
                        <span style={{color:'var(--gold-500)',flexShrink:0}}>—</span>
                        <span>{b}</span>
                      </li>
                    ))}
                  </ul>
                  <button className="btn btn-secondary" onClick={onRequest} style={{padding:'10px 20px',fontSize:13}}>Demander un devis</button>
                </div>
                <div className={'img-swap' + (v.imageUrl2 ? ' has-hover' : '')} style={{direction:'ltr',position:'relative'}}>
                  <img
                    src={v.imageUrl || '/ui_kits/public_site/assets/photo-cour-soir.webp'}
                    alt={v.title}
                    className="img-section"
                    style={{width:'100%',height:420,objectFit:'cover',borderRadius:6,boxShadow:'var(--shadow-md)'}}
                  />
                  {v.imageUrl2 && (
                    <img
                      src={v.imageUrl2}
                      alt=""
                      aria-hidden="true"
                      className="img-section img-swap-hover"
                      style={{width:'100%',height:420,objectFit:'cover',borderRadius:6}}
                    />
                  )}
                </div>
              </div>
            );
          })}
        </div>
      </div>
    </section>
  );
}
window.VocationsSection = VocationsSection;
