/* BoatsFun — Page Connexion (choix de rôle + formulaire mock). Expose window.BFPageConnexion. */

(function () {
  const { I } = window.BF;

  const styles = `
/* ===== HERO ===== */
.bf .cx-hero {
  background: #F0F8FF;
  padding: 48px 20px 36px;
  text-align: center;
}
.bf .cx-hero-inner { max-width: 560px; margin: 0 auto; }
.bf .cx-hero h1 {
  font-family: 'Poppins', sans-serif;
  font-size: 36px;
  font-weight: 800;
  color: #002244;
  margin: 0 0 12px;
  line-height: 1.15;
}
.bf .cx-hero .cx-sub {
  font-size: 17px;
  color: #6B7A8C;
  margin: 0;
  line-height: 1.6;
}

/* ===== MAIN ===== */
.bf .cx-main {
  background: #F0F8FF;
  padding: 0 20px 80px;
}
.bf .cx-wrap {
  max-width: 820px;
  margin: 0 auto;
}

/* ===== ROLE CHOICE CARDS ===== */
.bf .cx-choices {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  padding-top: 8px;
}
.bf .cx-role-card {
  background: #fff;
  border-radius: 20px;
  box-shadow: 0 8px 40px -12px rgba(0,34,68,.12);
  padding: 36px 32px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.bf .cx-role-icon {
  width: 48px;
  height: 48px;
  border-radius: 14px;
  background: #EAF6FF;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #00B5E2;
  margin-bottom: 4px;
}
.bf .cx-role-card h2 {
  font-family: 'Poppins', sans-serif;
  font-size: 20px;
  font-weight: 700;
  color: #002244;
  margin: 0;
}
.bf .cx-role-card p {
  font-size: 14.5px;
  color: #6B7A8C;
  line-height: 1.65;
  margin: 0;
}
.bf .cx-role-card a.cx-contact-link {
  font-size: 13.5px;
  color: #00B5E2;
  text-decoration: none;
  font-weight: 600;
}
.bf .cx-role-card a.cx-contact-link:hover { text-decoration: underline; }
.bf .cx-btn-role {
  display: inline-block;
  background: #FF8200;
  color: #fff;
  font-family: 'Poppins', sans-serif;
  font-weight: 600;
  font-size: 15px;
  padding: 12px 24px;
  border-radius: 40px;
  border: none;
  cursor: pointer;
  transition: background .2s;
  text-align: center;
  margin-top: 8px;
  width: 100%;
}
.bf .cx-btn-role:hover { background: #E56F00; }
.bf .cx-btn-role.secondary {
  background: #002244;
}
.bf .cx-btn-role.secondary:hover { background: #003366; }

/* ===== FORM SECTION ===== */
.bf .cx-form-wrap {
  max-width: 440px;
  margin: 8px auto 0;
}
.bf .cx-back-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13.5px;
  color: #6B7A8C;
  font-family: 'Inter', sans-serif;
  font-weight: 500;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0 0 20px;
  transition: color .15s;
}
.bf .cx-back-link:hover { color: #002244; }
.bf .cx-form-card {
  background: #fff;
  border-radius: 20px;
  box-shadow: 0 8px 40px -12px rgba(0,34,68,.13);
  padding: 36px 40px;
}
.bf .cx-form-card h2 {
  font-family: 'Poppins', sans-serif;
  font-size: 22px;
  font-weight: 700;
  color: #002244;
  margin: 0 0 28px;
  padding-bottom: 16px;
  border-bottom: 2px solid #E8F2FF;
}
.bf .cx-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 16px;
}
.bf .cx-field label {
  font-family: 'Poppins', sans-serif;
  font-size: 13px;
  font-weight: 600;
  color: #002244;
}
.bf .cx-field input {
  font-family: 'Inter', sans-serif;
  font-size: 14px;
  color: #111;
  background: #fff;
  border: 1px solid #D5DEE8;
  border-radius: 10px;
  padding: 12px 14px;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
  box-sizing: border-box;
  width: 100%;
}
.bf .cx-field input:focus {
  border-color: #00B5E2;
  box-shadow: 0 0 0 3px rgba(0,181,226,.12);
}
.bf .cx-forgot {
  font-size: 13px;
  color: #00B5E2;
  text-decoration: none;
  font-family: 'Inter', sans-serif;
  display: block;
  text-align: right;
  margin: -8px 0 20px;
}
.bf .cx-forgot:hover { text-decoration: underline; }
.bf .cx-remember {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  color: #002244;
  font-family: 'Inter', sans-serif;
  cursor: pointer;
  margin-bottom: 24px;
}
.bf .cx-remember input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: #FF8200;
  cursor: pointer;
  flex-shrink: 0;
}
.bf .cx-submit {
  width: 100%;
  background: #FF8200;
  color: #fff;
  font-family: 'Poppins', sans-serif;
  font-weight: 600;
  font-size: 16px;
  padding: 14px;
  border-radius: 40px;
  border: none;
  cursor: pointer;
  transition: background .2s;
}
.bf .cx-submit:hover { background: #E56F00; }

/* ===== CONFIRMATION ===== */
.bf .cx-confirm {
  text-align: center;
  padding: 20px 0 12px;
}
.bf .cx-confirm .cx-conf-icon {
  width: 56px;
  height: 56px;
  background: #F0FFF8;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 18px;
  font-size: 26px;
}
.bf .cx-confirm h3 {
  font-family: 'Poppins', sans-serif;
  font-size: 20px;
  font-weight: 700;
  color: #002244;
  margin: 0 0 10px;
}
.bf .cx-confirm p {
  font-size: 14px;
  color: #6B7A8C;
  line-height: 1.7;
  margin: 0;
}

/* ===== RESPONSIVE ===== */
@media (max-width: 720px) {
  .bf .cx-hero h1 { font-size: 28px; }
  .bf .cx-form-card { padding: 28px 24px; }
}
@media (max-width: 600px) {
  .bf .cx-choices { grid-template-columns: 1fr; }
  .bf .cx-role-card { padding: 28px 24px; }
}
@media (max-width: 500px) {
  .bf .cx-form-card { padding: 24px 18px; }
}
`;

  function BFPageConnexion() {
    const [role, setRole] = React.useState(null);
    const [submitted, setSubmitted] = React.useState(false);

    function handleSubmit(e) {
      e.preventDefault();
      setSubmitted(true);
      setTimeout(() => {
        window.BF.nav(role === "client" ? "/dashboard-client" : "/dashboard-hote");
      }, 800);
    }

    return (
      <div className="bf">
        <style>{styles}</style>
        <window.BFHeader />

        {/* ===== HERO ===== */}
        <section className="cx-hero">
          <div className="cx-hero-inner">
            <h1>Se connecter à BoatsFun</h1>
            {role === null && (
              <p className="cx-sub">Accédez à votre espace client ou propriétaire.</p>
            )}
          </div>
        </section>

        {/* ===== MAIN ===== */}
        <section className="cx-main">
          <div className="cx-wrap">

            {/* ── Choix de rôle ── */}
            {role === null && (
              <div className="cx-choices">
                {/* Card Client */}
                <div className="cx-role-card">
                  <div className="cx-role-icon"><I.user width="22" /></div>
                  <h2>Je suis client</h2>
                  <p>Votre compte client est créé automatiquement après une réservation ou un paiement. Connectez-vous pour accéder à vos réservations et offres.</p>
                  <button type="button" className="cx-btn-role" onClick={() => setRole("client")}>
                    Continuer comme client
                  </button>
                </div>

                {/* Card Propriétaire */}
                <div className="cx-role-card">
                  <div className="cx-role-icon"><I.fleet width="22" /></div>
                  <h2>Je suis propriétaire</h2>
                  <p>Votre compte propriétaire est créé par BoatsFun après validation manuelle. Si vous n'avez pas encore vos accès, contactez-nous.</p>
                  <a href="/contact" className="cx-contact-link">Contacter BoatsFun →</a>
                  <button type="button" className="cx-btn-role secondary" onClick={() => setRole("hote")}>
                    Continuer comme propriétaire
                  </button>
                </div>
              </div>
            )}

            {/* ── Formulaire de connexion ── */}
            {role !== null && (
              <div className="cx-form-wrap">
                <button type="button" className="cx-back-link" onClick={() => { setRole(null); setSubmitted(false); }}>
                  ← Changer de profil
                </button>
                <div className="cx-form-card">
                  {submitted ? (
                    <div className="cx-confirm">
                      <div className="cx-conf-icon">✓</div>
                      <h3>Connexion réussie.</h3>
                      <p>Redirection vers votre espace…</p>
                    </div>
                  ) : (
                    <>
                      <h2>Connexion {role === "client" ? "client" : "propriétaire"}</h2>
                      <form onSubmit={handleSubmit} encType="multipart/form-data">
                        <div className="cx-field">
                          <label htmlFor="email">Courriel</label>
                          <input type="email" id="email" name="email" required placeholder="votre@email.com" />
                        </div>
                        <div className="cx-field">
                          <label htmlFor="mot_de_passe">Mot de passe</label>
                          <input type="password" id="mot_de_passe" name="mot_de_passe" required placeholder="••••••••" />
                        </div>
                        <a href="#" className="cx-forgot">Mot de passe oublié ?</a>
                        <label className="cx-remember">
                          <input type="checkbox" name="se_souvenir" />
                          Se souvenir de moi
                        </label>
                        <button type="submit" className="cx-submit">
                          Se connecter comme {role === "client" ? "client" : "propriétaire"}
                        </button>
                      </form>
                    </>
                  )}
                </div>
              </div>
            )}

          </div>
        </section>

        <window.BFFooter />
      </div>
    );
  }

  window.BFPageConnexion = BFPageConnexion;
})();
