/* ── Waitlist + Preorder + Transition + Categories + Metrics + Footer ── */

/* ── WAITLIST ── */
function WaitlistSection() {
  const [sent, setSent] = React.useState(false);
  const [loading, setLoading] = React.useState(false);

  async function handleSubmit(e) {
    e.preventDefault();setLoading(true);
    try {
      const r = await fetch(e.target.action, { method: "POST", body: new FormData(e.target), headers: { Accept: "application/json" } });
      if (r.ok) {setSent(true);e.target.reset();}
    } catch (_) {}
    setLoading(false);
  }

  const labelStyle = { display: "flex", flexDirection: "column", gap: "6px", fontSize: "11px", fontWeight: "var(--weight-medium)", color: "var(--text-muted)", letterSpacing: ".07em", textTransform: "uppercase" };
  const fieldStyle = { fontFamily: "var(--font-body)", fontSize: "var(--text-md)", color: "var(--text-heading)", background: "#fff", border: "1.5px solid var(--border-strong)", borderRadius: "var(--radius-md)", padding: "11px 14px", outline: "none", width: "100%" };

  return (
    <section id="waitlist" style={{ padding: "var(--space-8) 0", background: "var(--surface-page)" }}>
      <div className="wrap" style={{ maxWidth: "560px" }} data-comment-anchor="8d21fc4a5e-div-22-7">
        <span className="eyebrow">Liste d'attente</span>
        <h2 style={{ fontSize: "var(--text-3xl)", marginTop: "12px", marginBottom: "var(--space-3)" }}>Sois parmi les premiers.</h2>
        <p style={{ fontSize: "var(--text-md)", color: "var(--text-muted)", marginBottom: "var(--space-6)", maxWidth: "46ch" }}>
          On lance en 2027. Inscris-toi pour être prévenu·e en avant-première et rejoindre le crowdfunding dès son ouverture.
        </p>
        {sent ?
        <div style={{ padding: "24px", borderRadius: "var(--radius-lg)", background: "var(--glacier-tint)", border: "1px solid rgba(173,217,211,.4)", color: "#2b6b5a", fontSize: "var(--text-md)", fontWeight: "var(--weight-medium)" }}>
            Merci — tu es sur la liste. On te prévient dès l'ouverture&nbsp;!
          </div> :

        <form action="https://api.web3forms.com/submit" method="POST" onSubmit={handleSubmit}
        style={{ display: "grid", gridTemplateColumns: "1fr 1fr", gap: "14px" }}>
            <input type="hidden" name="access_key" value="083fc581-33f4-45a2-aa3d-5ee7e5c79a00" />
            <input type="hidden" name="subject" value="Nouvelle inscription waitlist — Refill Labs" />
            <input type="hidden" name="from_name" value="Site Refill Labs" />
            <input type="checkbox" name="botcheck" style={{ display: "none" }} tabIndex={-1} autoComplete="off" />
            <label style={labelStyle}>Prénom<input type="text" name="prenom" placeholder="Prénom" required autoComplete="given-name" style={fieldStyle} data-comment-anchor="cfab986fc6-input-35-45" /></label>
            <label style={labelStyle}>Email<input type="email" name="email" placeholder="prénom@example.com" required autoComplete="email" style={fieldStyle} data-comment-anchor="0c90fd3c79-input-36-44" /></label>
            <label style={{ ...labelStyle, gridColumn: "1/-1" }}>
              Tu t'intéresses à…
              <select name="categorie" style={{ ...fieldStyle, appearance: "none" }}>
                <option value="">— Choisir —</option>
                <option>Gels &amp; compotes</option>
                <option>Barres &amp; bonbons</option>
                <option>Protéines &amp; récupération</option>
                <option>Boissons &amp; hydratation</option>
                <option>Snacks &amp; oléagineux</option>
              </select>
            </label>
            <div style={{ gridColumn: "1/-1", display: "flex", flexDirection: "column", gap: "10px" }}>
              <label style={{ display: "flex", alignItems: "flex-start", gap: "10px", fontSize: "13px", fontWeight: "300", color: "var(--text-muted)", cursor: "pointer", textTransform: "none", letterSpacing: 0 }}>
                <input type="checkbox" name="crowdfunding" style={{ marginTop: "2px", accentColor: "var(--ink)" }} />
                M'avertir à l'ouverture du crowdfunding
              </label>
              <label style={{ display: "flex", alignItems: "flex-start", gap: "10px", fontSize: "13px", fontWeight: "300", color: "var(--text-muted)", cursor: "pointer", textTransform: "none", letterSpacing: 0 }}>
                <input type="checkbox" name="rgpd" required style={{ marginTop: "2px", accentColor: "var(--ink)" }} />
                J'accepte que mes données soient utilisées pour me tenir informé·e des actualités Refill Labs (RGPD).
              </label>
            </div>
            <div style={{ gridColumn: "1/-1" }}>
              <button type="submit" disabled={loading} style={{ fontFamily: "var(--font-body)", fontSize: "var(--text-md)", fontWeight: "var(--weight-medium)", padding: "14px 32px", borderRadius: "var(--radius-pill)", width: "100%", background: "var(--ink)", color: "#fff", border: "none", cursor: loading ? "default" : "pointer", opacity: loading ? 0.7 : 1 }}>
                {loading ? "Envoi…" : "Rejoindre la liste d'attente →"}
              </button>
            </div>
          </form>
        }
      </div>
    </section>);

}

/* ── PREORDER CARD ── */
function PreorderCard() {
  const cardBase = {
    background: "#fff", border: "1px solid var(--border-subtle)",
    borderRadius: "24px", padding: "40px 36px", textAlign: "center",
    boxShadow: "var(--shadow-raised)", flex: "1 1 320px", maxWidth: "380px"
  };
  const pill = (bg, color) => ({ display: "inline-flex", alignItems: "center", gap: "6px", fontSize: "11px", fontWeight: "var(--weight-medium)", letterSpacing: ".1em", textTransform: "uppercase", color, background: bg, padding: "6px 14px", borderRadius: "var(--radius-pill)", marginBottom: "20px" });
  const dot = (bg) => ({ width: "5px", height: "5px", borderRadius: "50%", background: bg, display: "inline-block" });
  const tiers = [
    { n: "10 recharges", price: "25", unit: "2,50", note: "", highlight: false },
    { n: "20 recharges", price: "40", unit: "2,00", note: "+ Barflask offerte", highlight: true },
    { n: "40 recharges", price: "68", unit: "1,70", note: "+ Barflask offerte", highlight: false },
  ];
  return (
    <section id="preorder" style={{ padding: "var(--space-8) 0", background: "var(--surface-alt)", borderTop: "1px solid var(--border-subtle)" }} data-comment-anchor="0f54d023c5-section-73-5">
      <div className="wrap" style={{ maxWidth: "860px", marginBottom: "var(--space-6)" }}>
        <span className="eyebrow">Précommande</span>
        <h2 style={{ fontSize: "var(--text-3xl)", marginTop: "12px" }}>Réserve dès maintenant.</h2>
        <p style={{ fontSize: "var(--text-md)", color: "var(--text-muted)", marginTop: "10px" }}>Livraison au démarrage de la production.</p>
      </div>
      <div className="wrap" style={{ maxWidth: "860px", display: "flex", gap: "var(--space-5)", justifyContent: "center", flexWrap: "wrap" }}>

        {/* Barflask card */}
        <div style={cardBase} data-comment-anchor="7b72909d8f-div-75-9">
          <span style={pill("var(--glacier-tint)", "#2b6b5a")}><span style={dot("var(--glacier)")} />Barflask</span>
          <div style={{ fontFamily: "var(--font-display)", fontWeight: "var(--weight-display)", fontSize: "var(--text-2xl)", color: "var(--text-heading)", letterSpacing: "-0.02em" }}>Barflask</div>
          <div style={{ fontFamily: "var(--font-display)", fontWeight: "var(--weight-display)", fontSize: "52px", color: "var(--text-heading)", letterSpacing: "-0.04em", lineHeight: 1, margin: "10px 0 6px" }}>19,90 €</div>
          <p style={{ fontSize: "var(--text-sm)", color: "var(--text-muted)", marginBottom: "20px", lineHeight: 1.5 }}>
            Le contenant souple conçu pour les solides.
          </p>
          <div style={{ display: "flex", flexDirection: "column", gap: "8px", marginBottom: "24px" }}>
            {[
              { f: "Ouverture à une main", v: "En cours de dépôt" },
              { f: "Durée de vie", v: "10 000 +" },
              { f: "Recharges incluses", v: "+5 au lancement" },
            ].map(r => (
              <div key={r.f} style={{ display: "flex", justifyContent: "space-between", alignItems: "center", padding: "10px 14px", borderRadius: "var(--radius-md)", background: "var(--neutral-50)", border: "1px solid var(--border-subtle)" }}>
                <span style={{ fontSize: "var(--text-sm)", color: "var(--text-muted)" }}>{r.f}</span>
                <span style={{ fontSize: "var(--text-sm)", fontWeight: "var(--weight-medium)", color: "var(--text-heading)" }}>{r.v}</span>
              </div>
            ))}
          </div>
          <a href="#waitlist" style={{ display: "block", fontFamily: "var(--font-body)", fontSize: "var(--text-md)", fontWeight: "var(--weight-medium)", padding: "14px 28px", borderRadius: "var(--radius-pill)", background: "var(--glacier)", color: "var(--ink)", textDecoration: "none" }}>Être prévenu·e du lancement →</a>
        </div>

        {/* Forfait card */}
        <div style={cardBase}>
          <span style={pill("var(--neutral-100)", "var(--ink)")}><span style={dot("var(--ink)")} />Forfait recharges</span>
          <div style={{ fontFamily: "var(--font-display)", fontWeight: "var(--weight-display)", fontSize: "var(--text-2xl)", color: "var(--text-heading)", letterSpacing: "-0.02em", marginBottom: "20px" }}>Forfait</div>
          <div style={{ display: "flex", flexDirection: "column", gap: "10px", marginBottom: "28px" }}>
            {tiers.map(t => (
              <div key={t.n} style={{ display: "flex", alignItems: "center", justifyContent: "space-between", padding: "12px 16px", borderRadius: "var(--radius-md)", background: t.highlight ? "var(--glacier-tint)" : "var(--neutral-50)", border: t.highlight ? "1.5px solid rgba(173,217,211,.5)" : "1px solid var(--border-subtle)" }}>
                <div style={{ textAlign: "left" }}>
                  <div style={{ fontSize: "var(--text-sm)", fontWeight: "var(--weight-medium)", color: "var(--text-heading)" }}>{t.n}</div>
                  {t.note && <div style={{ fontSize: "11px", color: "#2b6b5a", fontWeight: "var(--weight-medium)" }}>{t.note}</div>}
                </div>
                <div style={{ textAlign: "right" }}>
                  <div style={{ fontFamily: "var(--font-display)", fontWeight: "var(--weight-display)", fontSize: "var(--text-lg)", color: "var(--text-heading)" }}>{t.price} €</div>
                  <div style={{ fontSize: "11px", color: "var(--text-muted)" }}>{t.unit} €/recharge</div>
                </div>
              </div>
            ))}
          </div>
          <a href="#waitlist" style={{ display: "block", fontFamily: "var(--font-body)", fontSize: "var(--text-md)", fontWeight: "var(--weight-medium)", padding: "14px 28px", borderRadius: "var(--radius-pill)", background: "var(--ink)", color: "#fff", textDecoration: "none" }}>Être prévenu·e →</a>
          <p style={{ fontSize: "11px", color: "var(--text-muted)", marginTop: "12px" }}>À partir de 20 recharges — Barflask offerte incluse.</p>
        </div>

      </div>
    </section>
  );
}

/* ── WHITE TRANSITION BAR ── */
function WhiteBar() {
  return <div style={{ height: "2px", background: "var(--surface-page)" }} />;
}

/* ── MISSION ── */
function Categories() {
  const convictions = [
  { t: "Pour les sportifs", d: "S'alimenter aussi bien qu'avant, sans rien laisser derrière soi." },
  { t: "Pour la nature & les villes", d: "Moins de plastique non recyclable, des espaces plus propres." }];

  return (
    <section id="mission" style={{ padding: "var(--space-8) 0", background: "var(--surface-page)", borderTop: "1px solid var(--border-subtle)" }} data-comment-anchor="245576265b-section-108-5">
      <div className="wrap" style={{ maxWidth: "760px" }}>
        <span className="eyebrow">Notre mission</span>
        <h2 style={{ fontSize: "clamp(26px,4vw,44px)", marginTop: "14px", marginBottom: "var(--space-5)", letterSpacing: "-0.025em", lineHeight: 1.1 }}>
          Donner aux sportifs une façon de s'alimenter à l'effort, sans jeter un seul emballage.
        </h2>
        <p style={{ fontSize: "var(--text-md)", color: "var(--text-muted)", lineHeight: 1.75, marginBottom: "var(--space-7)", maxWidth: "64ch" }} data-comment-anchor="7b2a41a271-p-114-9">
          <em style={{ display: "block", fontSize: "var(--text-lg)", lineHeight: 1.6, color: "var(--text-heading)", fontStyle: "italic", marginBottom: "12px" }}>
            &laquo;&nbsp;C'est possible de faire des compétitions sans avoir un impact si grand. Il faut que l'on change le système, on a la capacité de le faire et il ne faut pas attendre d'avoir un mode de vie parfait, au contraire il faut vouloir changer.&nbsp;&raquo;
          </em>
          <span style={{ fontSize: "var(--text-sm)", fontWeight: "var(--weight-medium)", color: "var(--text-heading)" }}>Kilian Jornet</span>
        </p>
        <div style={{ display: "grid", gridTemplateColumns: "1fr 1fr", gap: "var(--space-4)" }}>
          {convictions.map((c) =>
          <div key={c.t} style={{ background: "var(--surface-alt)", border: "1px solid var(--border-subtle)", borderRadius: "var(--radius-lg)", padding: "var(--space-6)" }}>
              <h3 style={{ fontSize: "var(--text-lg)", fontWeight: "var(--weight-medium)", marginBottom: "var(--space-2)", color: "var(--text-heading)" }}>{c.t}</h3>
              <p style={{ margin: 0, fontSize: "var(--text-sm)", color: "var(--text-muted)", lineHeight: 1.65 }}>{c.d}</p>
            </div>
          )}
        </div>
      </div>
    </section>);

}

/* ── METRICS ── */
function Metrics() {
  const stats = [
  { v: "3 Md", d: "de déchets d'emballages individuels évités" },
  { v: "10 000+", d: "utilisation en rincant à l'eau" },
  { v: "0", d: "emballage en sortie de machine" }];

  return (
    <section style={{ background: "var(--surface-alt)", padding: "0 0 var(--space-8)", borderTop: "1px solid var(--border-subtle)" }} data-comment-anchor="daa8222107-section-143-5">
      <div className="wrap" style={{ display: "grid", gridTemplateColumns: "1fr 1.4fr", gap: "var(--space-8)", alignItems: "center", padding: "var(--space-7) 0" }} data-comment-anchor="2bf7197370-div-140-7">
        <div style={{ paddingLeft: "var(--space-6)" }}>
          <h2 style={{ fontSize: "var(--text-2xl)" }}>Des chiffres, pas des promesses.</h2>
          <blockquote style={{ margin: "var(--space-5) 0 0", padding: "0 0 0 var(--space-4)", borderLeft: "2px solid var(--border-strong)", fontStyle: "italic", fontSize: "var(--text-sm)", color: "var(--text-muted)", lineHeight: 1.7 }}>
            Sur mon 80 km, couru en 18 heures, j'ai consommé un produit toutes les 15 minutes. Soit 72 emballages sur une seule course. Multipliez par tous les traïleurs, marathoniens, cyclistes et athlètes d'endurance — on arrive à des Milliards d'emballages par an.*
          </blockquote>
        </div>
        <div style={{ display: "grid", gridTemplateColumns: "repeat(3,1fr)", gap: "var(--space-5)" }}>
          {stats.map((s) =>
          <div key={s.v} style={{ borderLeft: "1px solid var(--border-strong)", paddingLeft: "20px" }}>
              <div style={{ fontFamily: "var(--font-display)", fontWeight: "var(--weight-display)", fontSize: "var(--text-2xl)", color: "var(--text-heading)" }}>{s.v}</div>
              <div style={{ fontSize: "var(--text-sm)", color: "var(--text-muted)", marginTop: "6px" }}>{s.d}</div>
            </div>
          )}
        </div>
      </div>
    </section>);

}

/* ── FOOTER ── */
function SiteFooter() {
  const cols = [
  { h: "Produits", l: ["Barflask", "Ouvertures", "Recharges", "Accessoires"] },
  { h: "Refill Source", l: ["Trouver une Source", "Installer une Source", "Pour les pros"] },
  { h: "Refill Labs", l: ["Notre démarche", "Chiffres", "Presse", "Contact"] }];

  return (
    <footer style={{ borderTop: "1px solid var(--border-subtle)", paddingTop: "var(--space-7)" }}>
      <div className="wrap" style={{ display: "grid", gridTemplateColumns: "1.2fr repeat(3,1fr)", gap: "var(--space-6)", paddingBottom: "var(--space-7)" }}>
        <img src="assets/logo-wordmark-ink.png" alt="Refill Labs" style={{ height: "36px", justifySelf: "start" }} />
        {cols.map((c) =>
        <div key={c.h} style={{ display: "flex", flexDirection: "column", gap: "10px" }}>
            <h4 style={{ fontSize: "var(--text-sm)" }}>{c.h}</h4>
            {c.l.map((x) => <a key={x} href="#" style={{ textDecoration: "none", fontSize: "var(--text-sm)", color: "var(--text-muted)" }}>{x}</a>)}
          </div>
        )}
      </div>
      <div style={{ borderTop: "1px solid var(--border-subtle)" }}>
        <div className="wrap" style={{ display: "flex", justifyContent: "space-between", alignItems: "center", padding: "20px 32px" }}>
          <span style={{ fontSize: "var(--text-xs)", color: "var(--text-muted)" }}>© 2026 Refill Labs</span>
          <div style={{ display: "flex", gap: "var(--space-5)", fontSize: "var(--text-xs)", color: "var(--text-muted)" }}>
            <a href="#" style={{ color: "inherit" }}>Confidentialité</a>
            <a href="#" style={{ color: "inherit" }}>Mentions légales</a>
            <a href="#" style={{ color: "inherit" }}>Contact</a>
          </div>
        </div>
      </div>
    </footer>);

}

Object.assign(window, { WaitlistSection, PreorderCard, WhiteBar, Categories, Metrics, SiteFooter });