/* eslint-disable */
// MS BRIDGE — Hero v2 (restyle)
// Direction: dark hero (Mindly) + clean technical detailing (Insight).
// Sharp corners, two-tone ghost headline, beta urgency, social proof + handwritten note,
// VSL straddling the dark→light transition, tools marquee on the light side.
// Accent is tweakable: MS Bridge red vs reference orange.

;(function () {
const { useState, useEffect, useRef } = React;

/* ----------------------------- palette ----------------------------- */
const INK   = "#0B0B0C";       // hero dark base
const TXT_HI = "#F6F5F3";
const TXT_MD = "rgba(246,245,243,0.60)";
const TXT_LO = "rgba(246,245,243,0.38)";
const LIGHT  = "#FFFFFF";
const INK_L  = "#16150F";      // ink on light
const MID_L  = "#5C5A52";

const ACCENTS = {
  "#E8291C": { base: "#E8291C", dark: "#B5180C", glow: "rgba(232,41,28,0.20)", on: "#fff" },
  "#FF6200": { base: "#FF6200", dark: "#D65200", glow: "rgba(255,98,0,0.22)", on: "#fff" },
};

/* ----------------------------- atoms ----------------------------- */

function MonoLabel({ children, color = TXT_LO, style }) {
  return (
    <span style={{
      fontFamily: "'Geist Mono', monospace",
      fontSize: 12,
      letterSpacing: "0.12em",
      textTransform: "uppercase",
      color,
      ...style,
    }}>{children}</span>
  );
}

function ArrowIcon({ size = 15, color = "currentColor" }) {
  return (
    <svg width={size} height={size} viewBox="0 0 24 24" fill="none" aria-hidden>
      <path d="M5 12h14M13 6l6 6-6 6" stroke={color} strokeWidth="2.2"
            strokeLinecap="round" strokeLinejoin="round" />
    </svg>
  );
}

/* ----------------------------- nav ----------------------------- */

function Logo({ accent }) {
  return (
    <img src="assets/logo-msbridge-trim.png" alt="MS Bridge — Marketing & Sales"
         style={{ height: "auto", maxHeight: 48, width: "auto", display: "block" }} />
  );
}

const NAV = [
  { label: "Comment ça marche", href: "#how" },
  { label: "Programme Bêta", href: "beta-program.html" },
  { label: "Témoignages", href: "#proof" },
  { label: "Podcast", href: "podcast.html" },
  { label: "FAQ", href: "#faq" },
];

const getHref = (href) => {
  const isHome = !window.location.pathname.includes('beta-program') && 
                 !window.location.pathname.includes('podcast') && 
                 !window.location.pathname.includes('confirmation');
  if (href.startsWith('#')) {
    return isHome ? href : 'index.html' + href;
  }
  return href;
};

function Nav({ accent }) {
  const [open, setOpen] = useState(false);
  return (
    <div className="msb-nav-wrap">
      <div className="msb-nav" style={open ? {
        background: "transparent",
        border: "none",
        borderBottom: "1px solid rgba(0,0,0,0.08)",
        borderRadius: 0,
        boxShadow: "none",
        backdropFilter: "none",
        width: "100%",
        padding: "8px 0px 14px 0px",
      } : undefined}>
        <a href={getHref("#root")} style={{ textDecoration: "none", display: "inline-flex" }}><Logo accent={accent} /></a>
        <span className="msb-nav-div" />
        <nav className="msb-nav-links">
          {NAV.map((n) => (
            <a key={n.label} href={getHref(n.href)} style={{
              fontSize: 13.5, color: "#43423C", textDecoration: "none", fontWeight: 450, whiteSpace: "nowrap",
            }}>{n.label}</a>
          ))}
        </nav>
        <span className="msb-nav-div" />
        <a href="https://app.msbridge.io/login" className="msb-nav-login" style={{
          fontSize: 13, color: "#43423C", textDecoration: "none", fontWeight: 500, whiteSpace: "nowrap", 
          padding: "8px 14px", border: "1px solid rgba(0,0,0,0.15)", borderRadius: 7
        }}>Connexion</a>
        <a href="https://app.msbridge.io/signup" className="msb-nav-cta" style={{
          display: "inline-flex", alignItems: "center", gap: 7, background: accent.base, color: accent.on,
          fontSize: 13, fontWeight: 500, padding: "9px 15px", borderRadius: 7, textDecoration: "none",
          letterSpacing: "0.01em", whiteSpace: "nowrap",
        }}>Commencer gratuitement <ArrowIcon size={14} /></a>
        <button className={"msb-burger" + (open ? " open" : "")} onClick={() => setOpen((o) => !o)}
                aria-label="Menu" aria-expanded={open}>
          <span /><span /><span />
        </button>
      </div>
      {open && (
        <div className="msb-nav-menu">
          {NAV.map((n) => (
            <a key={n.label} href={getHref(n.href)} className="mlink" onClick={() => setOpen(false)}>
              {n.label}<ArrowIcon size={14} color="#9A9994" />
            </a>
          ))}
          <span className="mdiv" />
          <a href="https://app.msbridge.io/login" className="mlink" onClick={() => setOpen(false)}>
            Connexion
          </a>
          <a href="https://app.msbridge.io/signup" className="msb-menu-cta" onClick={() => setOpen(false)}
             style={{ background: accent.base, color: accent.on }}>
            Commencer gratuitement <ArrowIcon size={15} />
          </a>
        </div>
      )}
    </div>
  );
}

/* ----------------------------- urgency pill ----------------------------- */

function UrgencyPill({ accent }) {
  return (
    <div style={{
      display: "inline-flex", alignItems: "center", gap: 10,
      padding: "7px 14px 7px 12px", borderRadius: 999,
      border: "1px solid rgba(246,245,243,0.14)", background: "rgba(246,245,243,0.04)",
    }}>
      <span style={{ position: "relative", width: 7, height: 7, display: "inline-block" }}>
        <span style={{ position: "absolute", inset: 0, borderRadius: 999, background: accent.base }} />
        <span className="msb-ping" style={{ position: "absolute", inset: -3, borderRadius: 999, border: `1px solid ${accent.base}` }} />
      </span>
      <MonoLabel color={TXT_MD} style={{ fontSize: 11.5 }}>Bêta publique</MonoLabel>
    </div>
  );
}

/* ----------------------------- beta form ----------------------------- */

function BetaForm({ accent }) {
  const [loading, setLoading] = useState(false);

  const handleSubmit = async (e) => {
    e.preventDefault();
    setLoading(true);
    try {
      const data = new FormData(e.target);
      data.append("access_key", "bd1d8fa4-172c-4363-9436-9514e961cff1");
      const res = await fetch("https://api.web3forms.com/submit", {
        method: "POST",
        body: data,
        headers: { Accept: "application/json" }
      });
      if (res.ok) {
        window.location.href = "https://www.msbridge.io/confirmation.html";
      } else {
        setLoading(false);
      }
    } catch {
      setLoading(false);
    }
  };

  return (
    <div className="msb-form" style={{ justifyContent: "center" }}>
      <a href="https://app.msbridge.io/signup" style={{
        display: "inline-flex", alignItems: "center", justifyContent: "center", gap: 8,
        background: accent.base, color: accent.on, border: "none", borderRadius: 7,
        padding: "0 20px", height: 50, fontSize: 14.5, fontWeight: 500,
        textDecoration: "none", cursor: "pointer",
        whiteSpace: "nowrap", letterSpacing: "0.01em"
      }}>
        Commencer gratuitement <ArrowIcon size={15} />
      </a>
    </div>
  );
}

/* ----------------------------- social proof ----------------------------- */

const AV = [
  "linear-gradient(135deg,#f5d0b0,#b8794a)",
  "linear-gradient(135deg,#bcd3f0,#5577a8)",
  "linear-gradient(135deg,#d9c4ea,#8a6bb0)",
  "linear-gradient(135deg,#cfe6c2,#6f9c52)",
];

function SocialProof({ accent }) {
  return (
    <div className="msb-proof" style={{ display: "flex", alignItems: "center", justifyContent: "center", gap: 16, flexWrap: "wrap", width: "100%" }}>
      <span className="msb-proof-text" style={{ fontSize: 13.5, color: TXT_MD, whiteSpace: "nowrap", lineHeight: 1.45 }}>
        Déjà adopté par des équipes <span style={{ color: TXT_HI }}>marketing &amp; indépendant</span>
      </span>
      <span className="msb-hand" style={{ position: "relative", color: accent.base, marginLeft: 60, display: "inline-flex", flexDirection: "column", alignItems: "center" }}>
        Même logique pour les solopreneurs
        <svg width="30" height="40" viewBox="0 0 30 40" fill="none" aria-hidden style={{ position: "absolute", top: "100%", left: "50%", transform: "translateX(-50%)", marginTop: 4 }}>
          <path d="M15 2C9 12 22 22 15 36" stroke="currentColor" strokeWidth="1.8" strokeLinecap="round" />
          <path d="M15 36l-7-6M15 36l7-6" stroke="currentColor" strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round" />
        </svg>
      </span>
    </div>
  );
}

/* ----------------------------- VSL placeholder ----------------------------- */

function Vsl({ accent, isMobile }) {
  const iframeRef = useRef(null);
  const [isPlaying, setIsPlaying] = useState(false);

  useEffect(() => {
    if (!document.querySelector('script[src="https://player.vimeo.com/api/player.js"]')) {
      const script = document.createElement("script");
      script.src = "https://player.vimeo.com/api/player.js";
      script.async = true;
      document.body.appendChild(script);
    }
  }, []);

  const handlePlayClick = () => {
    if (window.Vimeo && window.Vimeo.Player && iframeRef.current) {
      const player = new window.Vimeo.Player(iframeRef.current);
      player.setVolume(1).catch(() => {});
      player.setCurrentTime(0).catch(() => {});
      player.play().catch(() => {});
    }
    setIsPlaying(true);
  };

  return (
    <div style={{ display: "flex", flexDirection: "column", alignItems: "flex-end", width: "100%" }}>
      <div 
        className="msb-vsl" 
        style={{ 
          padding: 2, 
          background: "linear-gradient(135deg, rgba(255,255,255,0.9) 0%, rgba(255,98,0,0.5) 100%)", 
          borderRadius: 14,
          position: "relative",
          boxShadow: "0 10px 40px -10px rgba(0,0,0,0.5)"
        }}
      >
        <div style={{ overflow: "hidden", borderRadius: 12, background: "#000", position: "relative", display: "flex", flexDirection: "column", width: "100%" }}>
          <div style={{ padding: "56.25% 0 0 0", position: "relative", width: "100%" }}>
            <iframe
              ref={iframeRef}
              src="https://player.vimeo.com/video/1199484690?badge=0&amp;autopause=0&amp;player_id=0&amp;app_id=58479&amp;autoplay=1&amp;muted=1&amp;loop=1"
              frameBorder="0"
              allow="autoplay; fullscreen; picture-in-picture; clipboard-write; encrypted-media; web-share"
              referrerPolicy="strict-origin-when-cross-origin"
              style={{ position: "absolute", top: 0, left: 0, width: "100%", height: "100%" }}
              title="Sequence 01_1"
            ></iframe>
          </div>
          
          {!isPlaying && (
            <div 
              style={{ position: "absolute", inset: 0, display: "flex", alignItems: "center", justifyContent: "center", cursor: "pointer", background: "transparent" }} 
              onClick={handlePlayClick}
            >
              <button aria-label="Lancer la vidéo" style={{
                width: 86, height: 86, borderRadius: 999,
                background: "#FF6200", color: "#fff", border: "none", cursor: "pointer",
                display: "inline-flex", alignItems: "center", justifyContent: "center",
                boxShadow: `0 14px 40px -8px #FF6200, 0 0 0 10px rgba(255,98,0,0.22)`,
                transition: "transform 0.2s ease"
              }}
              onMouseEnter={(e) => e.currentTarget.style.transform = "scale(1.05)"}
              onMouseLeave={(e) => e.currentTarget.style.transform = "scale(1)"}
              >
                <svg width="34" height="34" viewBox="0 0 24 24" fill="currentColor" style={{ marginLeft: 4 }}><path d="M8 5.5v13l11-6.5L8 5.5z" /></svg>
              </button>
            </div>
          )}
        </div>
      </div>
      <div style={{ marginTop: 8, paddingRight: 4 }}>
        <span style={{ fontFamily: "'Caveat', cursive", fontSize: 16, color: isMobile ? "rgba(255,255,255,0.4)" : "rgba(0,0,0,0.5)" }}>
          Présenté par Henri Priso Expert Marketing
        </span>
      </div>
    </div>
  );
}

/* ----------------------------- tools strip ----------------------------- */

const TL = (window.MSB && window.MSB.toolLogos) || {};
const TOOLS = [
  ["Microsoft Teams", TL.teams], ["Google Meet", TL.meet], ["Zoom", TL.zoom],
  ["Fireflies", TL.fireflies], ["Modjo", TL.modjo], ["Gong", TL.gong],
  ["Aircall", TL.aircall], ["Ringover", TL.ringover],
];

function ToolsStrip() {
  const dup = [...TOOLS, ...TOOLS];
  return (
    <div className="msb-marquee">
      <div className="msb-track">
        {dup.map(([name, src], i) => (
          <div key={i} style={{ display: "inline-flex", alignItems: "center", gap: 11, padding: "0 26px", whiteSpace: "nowrap", flexShrink: 0 }}>
            {src ? <img src={src} alt="" width="26" height="26" style={{ objectFit: "contain", borderRadius: 5, display: "block" }} /> : null}
            <span style={{ fontSize: 14.5, fontWeight: 500, color: "#3A3A37" }}>{name}</span>
          </div>
        ))}
      </div>
    </div>
  );
}

/* ----------------------------- hero ----------------------------- */

function useIsMobile() {
  const [isMobile, setIsMobile] = useState(window.innerWidth <= 760);
  useEffect(() => {
    const handleResize = () => setIsMobile(window.innerWidth <= 760);
    window.addEventListener("resize", handleResize);
    return () => window.removeEventListener("resize", handleResize);
  }, []);
  return isMobile;
}

function Hero({ accentKey, gridOpacity, ghost }) {
  const accent = ACCENTS[accentKey] || ACCENTS["#E8291C"];
  const isMobile = useIsMobile();
  return (
    <div style={{ background: LIGHT }}>
      <section className="msb-hero" style={{ background: INK }}>
        {/* grid + glow */}
        <div className="msb-grid" style={{ opacity: gridOpacity }} aria-hidden />
        <div className="msb-glow" style={{ background: `radial-gradient(1000px 460px at 50% -8%, ${accent.glow} 0%, transparent 62%)` }} aria-hidden />

        <Nav accent={accent} />

        {isMobile ? (
          <div className="msb-hero-inner" style={{ paddingBottom: 40, paddingLeft: 16, paddingRight: 16 }}>
            <MonoLabel color={TXT_LO} style={{ fontSize: "clamp(9px, 2.8vw, 11.5px)", whiteSpace: "nowrap" }}>(01) — l'IA ne remplacera jamais les humains</MonoLabel>

            <div style={{ marginTop: 12 }}>
              <UrgencyPill accent={accent} />
            </div>

            <h1 className="msb-h1">
              <span className="msb-line1">Votre prochain client est <span style={{ color: accent.base }}>déjà</span></span><br />
              <span className={ghost ? "msb-ghost" : undefined} style={ghost ? undefined : { color: TXT_HI }}>dans vos derniers appels.</span>
            </h1>

            <p className="msb-sub" style={{ fontSize: "clamp(10px, 3.2vw, 13px)", margin: "16px 0 0", padding: "0", lineHeight: 1.45, width: "100%", letterSpacing: "-0.01em" }}>
              Générez des leads grâce à ce que vos prospects vous disent en appel. MS Bridge capte vos conversations, extrait les pain points et crée une stratégie marketing 100% basé sur la réalité (Lead magnet, LinkedIn, TikTok..).
            </p>

            {/* VSL (Video) right below description */}
            <div style={{ width: "100%", maxWidth: 480, marginTop: 32, padding: "0 16px" }}>
              <Vsl accent={accent} isMobile={isMobile} />
            </div>

            {/* Email form + CTA below video */}
            <div style={{ width: "100%", maxWidth: 480, marginTop: 32, padding: "0 16px" }}>
              <BetaForm accent={accent} />
            </div>

            {/* Bottom note under CTA */}
            <div style={{ marginTop: 16 }}>
              <MonoLabel color={TXT_LO} style={{ fontSize: 11 }}>Essai gratuit. Sans carte bancaire.</MonoLabel>
            </div>
          </div>
        ) : (
          <div className="msb-hero-inner">
            <MonoLabel color={TXT_LO} style={{ fontSize: 11.5 }}>(01) — l'IA ne remplacera jamais les humains</MonoLabel>

            <div style={{ marginTop: 12 }}>
              <UrgencyPill accent={accent} />
            </div>

            <h1 className="msb-h1">
              <span className="msb-line1">Votre prochain client est <span style={{ color: accent.base }}>déjà</span></span><br />
              <span className={ghost ? "msb-ghost" : undefined} style={ghost ? undefined : { color: TXT_HI }}>dans vos derniers appels.</span>
            </h1>

            <p className="msb-sub" style={{ maxWidth: "860px" }}>
              Générez des leads grâce à ce que vos prospects vous disent en appel.<br />
              MS Bridge capte vos conversations, extrait les pain points et crée une stratégie<br />
              marketing 100% basé sur la réalité (Lead magnet, LinkedIn, TikTok..).
            </p>

            <div style={{ marginTop: 20 }}><BetaForm accent={accent} /></div>
            <div style={{ marginTop: 10 }}>
              <MonoLabel color={TXT_LO} style={{ fontSize: 11 }}>Essai gratuit. Sans carte bancaire.</MonoLabel>
            </div>

            <div style={{ marginTop: 20 }}><SocialProof accent={accent} /></div>
          </div>
        )}

        {!isMobile && <div style={{ height: 180 }} />}
      </section>

      {/* light side — VSL straddles the seam (desktop) or only tools strip (mobile) */}
      <section style={{ background: LIGHT, position: "relative" }}>
        {!isMobile && <div className="msb-vsl-wrap"><Vsl accent={accent} /></div>}
        <div className="msb-tools-row" style={isMobile ? { paddingTop: 24, paddingBottom: 24 } : undefined}>
          <MonoLabel color={MID_L} style={{ fontSize: 11.5 }}>→ Compatible avec vos outils</MonoLabel>
          <div style={{ flex: 1, minWidth: 0 }}><ToolsStrip /></div>
          <div style={{
            display: "inline-flex", alignItems: "center", gap: 6,
            padding: "6px 12px", borderRadius: 999,
            border: "1px solid rgba(0,0,0,0.08)", background: "rgba(0,0,0,0.02)",
            whiteSpace: "nowrap"
          }}>
            <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="#10b981" strokeWidth="2.5" strokeLinecap="round" strokeLinejoin="round"><path d="M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10z"/></svg>
            <span style={{ fontSize: 12, fontWeight: 500, color: MID_L }}>Solution RGPD Compliance</span>
          </div>
        </div>
      </section>
    </div>
  );
}

/* ----------------------------- export ----------------------------- */

Object.assign(window, { HeroV2: Hero, MSBNav: Nav });

})();
