/* global React */
const { useState: useStateL, useEffect: useEffectL } = React;

/* =========================================================
   POURQUOI MAINTENANT
========================================================= */
const Pourquoi = () => {
  const items = [
    {
      eyebrow: 'Le constat',
      title: "L'IA crée déjà un fossé interne.",
      body: "Dans la même PME, certains gagnent 2 heures par jour, d'autres n'osent pas ouvrir ChatGPT. Sans cadre, l'écart se creuse — et il devient politique."
    },
    {
      eyebrow: 'Le piège',
      title: "Les formations classiques ratent leur cible.",
      body: "Une journée présentielle, beaucoup de slides, peu de pratique. Trois mois plus tard : rien n'a changé dans le quotidien des équipes."
    },
    {
      eyebrow: 'La conviction',
      title: "Cinq minutes par jour, pendant douze semaines.",
      body: "Des cas réels métier, validés par un manager, ancrés dans un workflow déjà existant. C'est comme ça qu'un réflexe se construit — et qu'il dure."
    },
  ];

  return (
    <section style={{ background: 'var(--vert-sapin)', color: '#fff', position: 'relative', overflow: 'hidden' }}>
      {/* Decorative curve */}
      <svg style={{ position: 'absolute', bottom: -100, right: -100, width: 600, height: 600, opacity: 0.06, pointerEvents: 'none' }} viewBox="0 0 64 64">
        <path d="M 14 32 Q 28 60, 50 20" stroke="#FFFFFF" strokeWidth="2" fill="none" strokeLinecap="round" />
      </svg>

      <div className="container" style={{ position: 'relative' }}>
        <div style={{ maxWidth: 720, marginBottom: 64 }}>
          <span style={{ fontSize: 13, fontWeight: 500, letterSpacing: '0.08em', textTransform: 'uppercase', color: 'var(--vert-menthe)' }}>
            Pourquoi maintenant
          </span>
          <h2 className="t-h1" style={{ marginTop: 14, marginBottom: 16, color: '#fff' }}>
            On ne forme pas à l'IA<br/><em style={{ fontWeight: 700, color: 'var(--vert-menthe)' }}>comme on a formé à Excel.</em>
          </h2>
        </div>

        <div style={{ display: 'grid', gridTemplateColumns: 'repeat(3, 1fr)', gap: 32 }}>
          {items.map((it, i) => {
            const ill = ['assets/illus/paper-map.png', 'assets/illus/checklist.png', 'assets/illus/healthy-habit.png'][i];
            return (
              <div key={i} style={{
                padding: '32px 0',
                borderTop: '1px solid rgba(255, 255, 255, 0.18)',
              }}>
                <img src={ill} alt="" style={{ width: 200, height: 200, marginBottom: 20, marginLeft: -16, filter: 'brightness(1.1)' }} />
                <div style={{ fontSize: 12, letterSpacing: '0.1em', textTransform: 'uppercase', color: 'var(--vert-menthe)', fontWeight: 600, marginBottom: 16 }}>
                  0{i+1} · {it.eyebrow}
                </div>
                <h3 style={{ fontSize: 24, fontWeight: 700, lineHeight: 1.15, letterSpacing: '-0.02em', marginBottom: 16, color: '#fff' }}>
                  {it.title}
                </h3>
                <p style={{ fontSize: 16, lineHeight: 1.6, color: 'rgba(255, 255, 255, 0.78)', margin: 0 }}>
                  {it.body}
                </p>
              </div>
            );
          })}
        </div>
      </div>
    </section>
  );
};

/* =========================================================
   TARIFS APERÇU
========================================================= */
const TarifsAperçu = () => {
  const plans = [
    {
      name: 'Starter', price: '14 €', star: false,
      includes: ['Cursus Général', 'Tronc commun IA', 'Suivi managérial', 'Support email'],
      cta: 'Choisir Starter', ctaStyle: 'secondary',
    },
    {
      name: 'Pro', price: '24 €', star: true,
      includes: ['Les 3 cursus', 'Collectif & rituels', 'Certifications incluses', 'Customer success dédié'],
      cta: 'Demander une démo', ctaStyle: 'primary',
    },
    {
      name: 'Enterprise', price: 'Sur devis', star: false,
      includes: ['Tout Pro', 'Cas d\'usage sur-mesure', 'SSO & sécurité avancée', 'Pilotage groupe SRA'],
      cta: 'Nous contacter', ctaStyle: 'secondary',
    },
  ];

  return (
    <section>
      <div className="container">
        <div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'flex-end', marginBottom: 48, gap: 32, flexWrap: 'wrap' }}>
          <div style={{ maxWidth: 560 }}>
            <span className="t-eyebrow">Tarifs</span>
            <h2 className="t-h1" style={{ marginTop: 14, marginBottom: 16 }}>
              Premium accessible. <span className="italic-accent">Pas premium élitiste.</span>
            </h2>
            <p className="t-body-lg" style={{ margin: 0 }}>
              Tarif annuel, paiement mensuel. Dégressif au-delà de 100 utilisateurs.
            </p>
          </div>
          <div style={{ fontSize: 13, color: 'var(--texte-mute)' }}>Par utilisateur · par mois · HT</div>
        </div>

        <div style={{ display: 'grid', gridTemplateColumns: 'repeat(3, 1fr)', gap: 20 }}>
          {plans.map(p => (
            <div key={p.name} className="card" style={{
              padding: 32,
              background: p.star ? 'var(--vert-sapin)' : 'var(--blanc)',
              color: p.star ? '#fff' : 'var(--texte)',
              borderColor: p.star ? 'var(--vert-sapin)' : 'var(--hairline)',
              position: 'relative',
              transform: p.star ? 'translateY(-12px)' : 'none',
              boxShadow: p.star ? '0 30px 60px -25px rgba(15, 51, 41, 0.4)' : 'none',
            }}>
              {p.star && (
                <div style={{
                  position: 'absolute', top: -14, left: 32,
                  background: 'var(--vert-menthe)', color: 'var(--vert-sapin)',
                  padding: '6px 12px', borderRadius: 999,
                  fontSize: 12, fontWeight: 700, letterSpacing: '0.04em', textTransform: 'uppercase',
                }}>★ Recommandé</div>
              )}
              <div style={{ fontSize: 22, fontWeight: 700, letterSpacing: '-0.01em' }}>{p.name}</div>
              <div style={{ display: 'flex', alignItems: 'baseline', gap: 6, marginTop: 28, marginBottom: 28 }}>
                <span style={{ fontSize: 44, fontWeight: 800, letterSpacing: '-0.03em', lineHeight: 1 }}>{p.price}</span>
                {p.price !== 'Sur devis' && <span style={{ fontSize: 14, color: p.star ? 'rgba(255,255,255,0.6)' : 'var(--texte-mute)' }}>/util/mois</span>}
              </div>
              <div style={{ height: 1, background: p.star ? 'rgba(255,255,255,0.18)' : 'var(--hairline)', marginBottom: 24 }} />
              <ul style={{ listStyle: 'none', padding: 0, margin: 0, display: 'flex', flexDirection: 'column', gap: 12 }}>
                {p.includes.map((it, i) => (
                  <li key={i} style={{ display: 'flex', gap: 10, alignItems: 'flex-start', fontSize: 14 }}>
                    <svg width="18" height="18" viewBox="0 0 18 18" fill="none" style={{ flexShrink: 0, marginTop: 1 }}>
                      <circle cx="9" cy="9" r="9" fill={p.star ? 'rgba(255,255,255,0.18)' : 'var(--vert-menthe-soft)'} />
                      <path d="M5 9.2L7.5 11.5L13 6" stroke={p.star ? '#fff' : 'var(--vert-sapin)'} strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round" fill="none"/>
                    </svg>
                    <span>{it}</span>
                  </li>
                ))}
              </ul>
              <a href="#" onClick={(e) => { e.preventDefault(); window.openVirageDemo(); }} className={p.ctaStyle === 'primary' ? 'btn' : 'btn'} style={{
                marginTop: 28, width: '100%', justifyContent: 'center',
                background: p.star ? '#fff' : (p.ctaStyle === 'primary' ? 'var(--vert-sapin)' : 'transparent'),
                color: p.star ? 'var(--vert-sapin)' : (p.ctaStyle === 'primary' ? '#fff' : 'var(--texte)'),
                border: p.star ? 'none' : (p.ctaStyle === 'primary' ? 'none' : '1.5px solid var(--hairline-strong)'),
                padding: '14px 22px', borderRadius: 999, fontWeight: 600, fontSize: 15,
              }}>
                {p.cta}
              </a>
            </div>
          ))}
        </div>
      </div>
    </section>
  );
};

/* =========================================================
   MANIFESTE EXTRAIT
========================================================= */
const ManifesteExtrait = () => {
  const valeurs = [
    { name: 'Bienveillance', body: "On ne juge pas un collaborateur qui n'a jamais ouvert ChatGPT. On l'accompagne." },
    { name: 'Authenticité',  body: "Pas de promesses miracles. Pas de buzzwords. Des cas réels, validés par leurs pairs." },
    { name: 'Humanité',      body: "L'IA n'est pas un remplacement. C'est un levier — pour celles et ceux qui font tourner l'entreprise." },
  ];

  return (
    <section style={{ background: 'var(--blanc)' }}>
      <div className="container">
        <div style={{ display: 'grid', gridTemplateColumns: '1fr 1.2fr', gap: 80, alignItems: 'center' }}>
          <div>
            <span className="t-eyebrow">Manifeste</span>
            <h2 className="t-h1" style={{ marginTop: 14, marginBottom: 24 }}>
              Donner à chacun sa place dans le <span className="italic-accent">virage IA.</span>
            </h2>
            <p className="t-body-lg" style={{ marginBottom: 28 }}>
              Le groupe SRA accompagne les PME françaises depuis quarante ans.
              On a vu passer le PC, le cloud, le SaaS. Aucune de ces vagues n'a
              laissé autant de monde sur le quai que celle qui arrive.
            </p>
            <a href="/manifeste" className="ulink" style={{ fontWeight: 600, color: 'var(--vert-sapin)' }}>
              Lire le manifeste complet →
            </a>
            <img src="assets/illus/community.png" alt="" style={{ width: '100%', maxWidth: 480, marginTop: 36, display: 'block' }} />
          </div>

          <div style={{ display: 'flex', flexDirection: 'column', gap: 16 }}>
            {valeurs.map((v, i) => (
              <div key={v.name} style={{
                display: 'grid', gridTemplateColumns: '60px 1fr', gap: 24,
                padding: '24px 0',
                borderTop: '1px solid var(--hairline)',
                borderBottom: i === valeurs.length - 1 ? '1px solid var(--hairline)' : 'none',
              }}>
                <div style={{
                  fontFamily: "'JetBrains Mono', ui-monospace, monospace",
                  fontSize: 13, color: 'var(--texte-mute)', paddingTop: 4,
                }}>
                  0{i + 1}
                </div>
                <div>
                  <h3 style={{ fontSize: 22, fontWeight: 700, letterSpacing: '-0.015em', margin: '0 0 8px' }}>
                    {v.name}
                  </h3>
                  <p style={{ fontSize: 15, lineHeight: 1.6, color: 'var(--texte-soft)', margin: 0 }}>
                    {v.body}
                  </p>
                </div>
              </div>
            ))}
          </div>
        </div>
      </div>
    </section>
  );
};

/* =========================================================
   NEWSLETTER
========================================================= */
const Newsletter = () => {
  const [email, setEmail] = useStateL('');
  const [submitted, setSubmitted] = useStateL(false);
  return (
    <section id="newsletter">
      <div className="container">
        <div style={{
          padding: '64px 56px', borderRadius: 32,
          background: 'var(--creme-deep)',
          display: 'grid', gridTemplateColumns: '1.1fr 1fr', gap: 56, alignItems: 'center',
          border: '1px solid var(--hairline)',
        }}>
          <div style={{ position: 'relative' }}>
            <span className="t-eyebrow">Newsletter</span>
            <h2 className="t-h1" style={{ marginTop: 14, marginBottom: 16 }}>
              Une fois par semaine, le virage IA <span className="italic-accent">à hauteur de PME.</span>
            </h2>
            <p className="t-body-lg" style={{ marginBottom: 0, maxWidth: 480 }}>
              Un cas concret, un outil testé en interne, une question reçue de
              dirigeant. Pas de fluff, pas d'auto-promotion. 2 300 abonnés.
            </p>
          </div>
          <div>
            {!submitted ? (
              <form onSubmit={(e) => { e.preventDefault(); if (email.includes('@')) setSubmitted(true); }}
                style={{ display: 'flex', flexDirection: 'column', gap: 12 }}>
                <div style={{ display: 'flex', gap: 8, padding: 6, background: '#fff', borderRadius: 999, border: '1px solid var(--hairline)' }}>
                  <input
                    type="email" required
                    value={email}
                    onChange={(e) => setEmail(e.target.value)}
                    placeholder="prenom@entreprise.fr"
                    style={{
                      flex: 1, border: 0, outline: 'none', background: 'transparent',
                      padding: '12px 18px', fontSize: 15, fontFamily: 'inherit', color: 'var(--texte)',
                    }} />
                  <button type="submit" className="btn btn-primary" style={{ padding: '12px 22px' }}>
                    S'abonner
                  </button>
                </div>
                <div style={{ fontSize: 12, color: 'var(--texte-mute)', paddingLeft: 8 }}>
                  Une seule édition par semaine. Désabonnement en 1 clic.
                </div>
              </form>
            ) : (
              <div style={{
                padding: '20px 24px', background: 'var(--vert-menthe-soft)', borderRadius: 16,
                display: 'flex', alignItems: 'center', gap: 14,
              }}>
                <Picto size={36} variant="menthe" />
                <div>
                  <div style={{ fontWeight: 600, fontSize: 16 }}>Bienvenue à bord !</div>
                  <div style={{ fontSize: 14, color: 'var(--texte-soft)' }}>
                    Premier numéro dans votre boîte vendredi prochain.
                  </div>
                </div>
              </div>
            )}
          </div>
        </div>
      </div>
    </section>
  );
};

/* =========================================================
   CTA FINAL
========================================================= */
const CTAFinal = () => (
  <section id="demo" style={{ paddingTop: 0 }}>
    <div className="container">
      <div style={{
        padding: '80px 56px', borderRadius: 32,
        background: 'var(--vert-sapin)', color: '#fff',
        position: 'relative', overflow: 'hidden',
        textAlign: 'center',
      }}>
        <svg style={{ position: 'absolute', top: -120, left: -120, width: 400, height: 400, opacity: 0.08, pointerEvents: 'none' }} viewBox="0 0 64 64">
          <path d="M 14 32 Q 28 60, 50 20" stroke="#FFFFFF" strokeWidth="2" fill="none" strokeLinecap="round" />
        </svg>
        <svg style={{ position: 'absolute', bottom: -120, right: -120, width: 400, height: 400, opacity: 0.08, pointerEvents: 'none', transform: 'scaleX(-1)' }} viewBox="0 0 64 64">
          <path d="M 14 32 Q 28 60, 50 20" stroke="#FFFFFF" strokeWidth="2" fill="none" strokeLinecap="round" />
        </svg>

        <div style={{ position: 'relative', maxWidth: 720, margin: '0 auto' }}>
          <Picto size={56} variant="blanc" />
          <h2 className="t-h1" style={{ marginTop: 24, marginBottom: 20, color: '#fff' }}>
            On vous montre la plateforme<br/>en <em style={{ fontWeight: 700, color: 'var(--vert-menthe)' }}>vingt minutes.</em>
          </h2>
          <p style={{ fontSize: 18, lineHeight: 1.6, color: 'rgba(255,255,255,0.8)', marginBottom: 32 }}>
            Démo personnalisée selon votre contexte métier.
            Conduite par un humain qui connaît les PME.
          </p>
          <div style={{ display: 'flex', gap: 12, justifyContent: 'center', flexWrap: 'wrap' }}>
            <a href="#" onClick={(e) => { e.preventDefault(); window.openVirageDemo(); }} className="btn" style={{
              background: '#fff', color: 'var(--vert-sapin)',
              padding: '16px 28px', fontSize: 16,
            }}>
              Réserver un créneau
              <svg className="arrow" width="14" height="14" viewBox="0 0 14 14" fill="none">
                <path d="M2 7h10M8 3l4 4-4 4" stroke="currentColor" strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round"/>
              </svg>
            </a>
            <a href="#" onClick={(e) => { e.preventDefault(); window.openVirageDemo(); }} className="btn" style={{
              background: 'transparent', color: '#fff',
              border: '1.5px solid rgba(255,255,255,0.3)',
              padding: '16px 28px', fontSize: 16,
            }}>
              Parler à l'équipe
            </a>
          </div>
        </div>
      </div>
    </div>
  </section>
);

/* =========================================================
   FOOTER
========================================================= */
const Footer = () => (
  <footer style={{ borderTop: '1px solid var(--hairline)', padding: '64px 0 40px' }}>
    <div className="container">
      <div style={{ display: 'grid', gridTemplateColumns: '1.4fr 1fr 1fr 1fr', gap: 48, marginBottom: 56 }}>
        <div>
          <Logo size={36} />
          <p style={{ fontSize: 14, color: 'var(--texte-soft)', marginTop: 18, lineHeight: 1.6, maxWidth: 320 }}>
            La plateforme IA qui fait monter en compétences toutes les équipes.
            Conçu par le groupe SRA. À hauteur d'humain.
          </p>
        </div>
        <FooterCol title="Produit" items={[
          { label: 'Les 3 cursus', href: '/produit' },
          { label: 'Tarifs', href: '/tarifs' },
          { label: 'Certifications', href: '/produit' },
          { label: 'Demander une démo', onClick: () => window.openVirageDemo && window.openVirageDemo() },
        ]} />
        <FooterCol title="Ressources" items={[
          { label: 'Manifeste', href: '/manifeste' },
          { label: 'Newsletter', href: '/newsletter' },
          { label: 'FAQ', href: '/faq' },
          { label: 'Se connecter', href: 'https://app.virage.dev/login' },
        ]} />
        <FooterCol title="Groupe SRA" items={[
          { label: 'À propos', href: 'https://www.groupe-sra.fr', external: true },
          { label: 'Contact', onClick: () => window.openVirageDemo && window.openVirageDemo() },
          { label: 'Mentions légales', href: '#' },
          { label: 'Confidentialité', href: '#' },
        ]} />
      </div>
      <div style={{
        borderTop: '1px solid var(--hairline)', paddingTop: 24,
        display: 'flex', justifyContent: 'space-between', alignItems: 'center', flexWrap: 'wrap', gap: 16,
      }}>
        <div style={{ fontSize: 13, color: 'var(--texte-mute)' }}>
          © 2026 Virage · Une marque du groupe SRA · 40 ans au service des PME françaises
        </div>
        <div style={{ display: 'flex', gap: 16, alignItems: 'center', fontSize: 13, color: 'var(--texte-mute)' }}>
          <span>🇫🇷 Made in France</span>
          <span>·</span>
          <span>Qualiopi certifié</span>
          <span>·</span>
          <span>RGPD</span>
        </div>
      </div>
    </div>
  </footer>
);

const FooterCol = ({ title, items }) => (
  <div>
    <div style={{ fontSize: 13, fontWeight: 600, letterSpacing: '0.06em', textTransform: 'uppercase', color: 'var(--texte)', marginBottom: 16 }}>
      {title}
    </div>
    <ul style={{ listStyle: 'none', padding: 0, margin: 0, display: 'flex', flexDirection: 'column', gap: 10 }}>
      {items.map((it) => {
        const linkStyle = { fontSize: 14, color: 'var(--texte-soft)', transition: 'color 150ms ease', cursor: 'pointer' };
        const onOver = (e) => e.currentTarget.style.color = 'var(--vert-sapin)';
        const onOut = (e) => e.currentTarget.style.color = 'var(--texte-soft)';
        return (
          <li key={it.label}>
            {it.onClick ? (
              <a onClick={(e) => { e.preventDefault(); it.onClick(); }} href="#"
                 style={linkStyle} onMouseOver={onOver} onMouseOut={onOut}>{it.label}</a>
            ) : (
              <a href={it.href || '#'}
                 target={it.external ? '_blank' : undefined}
                 rel={it.external ? 'noopener noreferrer' : undefined}
                 style={linkStyle} onMouseOver={onOver} onMouseOut={onOut}>{it.label}</a>
            )}
          </li>
        );
      })}
    </ul>
  </div>
);

window.Pourquoi = Pourquoi;
window.TarifsAperçu = TarifsAperçu;
window.ManifesteExtrait = ManifesteExtrait;
window.Newsletter = Newsletter;
window.CTAFinal = CTAFinal;
window.Footer = Footer;
