import { jsx as e, jsxs as a, Fragment as S } from "react/jsx-runtime";
import { useState as n } from "react";
import { useNavigate as q } from "react-router-dom";
import { useTranslation as L } from "react-i18next";
import { CheckCircle as b, Lock as M, AlertTriangle as T, EyeOff as p, Eye as w, Loader2 as $ } from "lucide-react";
import { a as D } from "./index-Bs-WcWsP.js";
function H() {
  const { t: o } = L(), y = q(), [l, v] = n(""), [s, N] = n(""), [d, k] = n(""), [i, P] = n(!1), [c, C] = n(!1), [m, h] = n(!1), [g, u] = n(null), [A, j] = n(!1), z = ((r) => {
    const t = [];
    return r.length < 8 && t.push("Au moins 8 caractères"), /[A-Z]/.test(r) || t.push("Au moins une majuscule"), /[a-z]/.test(r) || t.push("Au moins une minuscule"), /[0-9]/.test(r) || t.push("Au moins un chiffre"), t;
  })(s), f = s === d && z.length === 0 && l.length > 0, E = async (r) => {
    if (r.preventDefault(), !!f) {
      h(!0), u(null);
      try {
        await D.changePassword(l, s), j(!0), setTimeout(() => {
          y("/");
        }, 2e3);
      } catch (t) {
        t instanceof Error ? u(t.message) : u("Une erreur est survenue");
      } finally {
        h(!1);
      }
    }
  };
  return A ? /* @__PURE__ */ e("div", { className: "min-h-screen flex items-center justify-center bg-gradient-to-br from-blue-50 to-indigo-100 dark:from-gray-900 dark:to-gray-800 p-4", children: /* @__PURE__ */ a("div", { className: "w-full max-w-md bg-white dark:bg-gray-800 rounded-2xl shadow-xl p-8 text-center", children: [
    /* @__PURE__ */ e("div", { className: "w-16 h-16 bg-green-100 dark:bg-green-900/30 rounded-full flex items-center justify-center mx-auto mb-4", children: /* @__PURE__ */ e(b, { className: "w-8 h-8 text-green-600 dark:text-green-400" }) }),
    /* @__PURE__ */ e("h2", { className: "text-2xl font-bold text-gray-900 dark:text-white mb-2", children: "Mot de passe modifié" }),
    /* @__PURE__ */ e("p", { className: "text-gray-600 dark:text-gray-400", children: "Vous allez être redirigé vers l'accueil..." })
  ] }) }) : /* @__PURE__ */ e("div", { className: "min-h-screen flex items-center justify-center bg-gradient-to-br from-blue-50 to-indigo-100 dark:from-gray-900 dark:to-gray-800 p-4", children: /* @__PURE__ */ e("div", { className: "w-full max-w-md", children: /* @__PURE__ */ a("div", { className: "bg-white dark:bg-gray-800 rounded-2xl shadow-xl p-8", children: [
    /* @__PURE__ */ a("div", { className: "text-center mb-8", children: [
      /* @__PURE__ */ e("div", { className: "w-16 h-16 bg-amber-100 dark:bg-amber-900/30 rounded-full flex items-center justify-center mx-auto mb-4", children: /* @__PURE__ */ e(M, { className: "w-8 h-8 text-amber-600 dark:text-amber-400" }) }),
      /* @__PURE__ */ e("h1", { className: "text-2xl font-bold text-gray-900 dark:text-white", children: o("auth.forceChangePassword.title", "Changement de mot de passe requis") }),
      /* @__PURE__ */ e("p", { className: "text-gray-600 dark:text-gray-400 mt-2", children: o("auth.forceChangePassword.description", "Pour des raisons de sécurité, vous devez définir un nouveau mot de passe.") })
    ] }),
    g && /* @__PURE__ */ a("div", { className: "mb-6 p-4 rounded-xl bg-red-100 dark:bg-red-900/30 text-red-700 dark:text-red-300 flex items-center gap-2", children: [
      /* @__PURE__ */ e(T, { className: "w-5 h-5 flex-shrink-0" }),
      /* @__PURE__ */ e("span", { children: g })
    ] }),
    /* @__PURE__ */ a("form", { onSubmit: E, className: "space-y-6", children: [
      /* @__PURE__ */ a("div", { children: [
        /* @__PURE__ */ e("label", { className: "block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1", children: o("auth.forceChangePassword.currentPassword", "Mot de passe actuel (temporaire)") }),
        /* @__PURE__ */ a("div", { className: "relative", children: [
          /* @__PURE__ */ e(
            "input",
            {
              type: i ? "text" : "password",
              required: !0,
              value: l,
              onChange: (r) => v(r.target.value),
              className: "w-full px-4 py-3 rounded-xl border border-gray-300 dark:border-gray-600 bg-white dark:bg-gray-700 text-gray-900 dark:text-white focus:outline-none focus:ring-2 focus:ring-blue-500",
              placeholder: "Entrez le mot de passe fourni par l'administrateur"
            }
          ),
          /* @__PURE__ */ e(
            "button",
            {
              type: "button",
              onClick: () => P(!i),
              className: "absolute right-3 top-1/2 -translate-y-1/2 text-gray-500 hover:text-gray-700 dark:hover:text-gray-300",
              children: i ? /* @__PURE__ */ e(p, { className: "w-5 h-5" }) : /* @__PURE__ */ e(w, { className: "w-5 h-5" })
            }
          )
        ] })
      ] }),
      /* @__PURE__ */ a("div", { children: [
        /* @__PURE__ */ e("label", { className: "block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1", children: o("auth.forceChangePassword.newPassword", "Nouveau mot de passe") }),
        /* @__PURE__ */ a("div", { className: "relative", children: [
          /* @__PURE__ */ e(
            "input",
            {
              type: c ? "text" : "password",
              required: !0,
              value: s,
              onChange: (r) => N(r.target.value),
              className: "w-full px-4 py-3 rounded-xl border border-gray-300 dark:border-gray-600 bg-white dark:bg-gray-700 text-gray-900 dark:text-white focus:outline-none focus:ring-2 focus:ring-blue-500",
              placeholder: "Choisissez un nouveau mot de passe"
            }
          ),
          /* @__PURE__ */ e(
            "button",
            {
              type: "button",
              onClick: () => C(!c),
              className: "absolute right-3 top-1/2 -translate-y-1/2 text-gray-500 hover:text-gray-700 dark:hover:text-gray-300",
              children: c ? /* @__PURE__ */ e(p, { className: "w-5 h-5" }) : /* @__PURE__ */ e(w, { className: "w-5 h-5" })
            }
          )
        ] }),
        s && /* @__PURE__ */ e("div", { className: "mt-2 space-y-1", children: ["Au moins 8 caractères", "Au moins une majuscule", "Au moins une minuscule", "Au moins un chiffre"].map((r, t) => {
          const x = [
            s.length >= 8,
            /[A-Z]/.test(s),
            /[a-z]/.test(s),
            /[0-9]/.test(s)
          ];
          return /* @__PURE__ */ a("div", { className: `flex items-center gap-2 text-sm ${x[t] ? "text-green-600" : "text-gray-500"}`, children: [
            x[t] ? /* @__PURE__ */ e(b, { className: "w-4 h-4" }) : /* @__PURE__ */ e("div", { className: "w-4 h-4 rounded-full border border-current" }),
            r
          ] }, `pwd-req-${t}`);
        }) })
      ] }),
      /* @__PURE__ */ a("div", { children: [
        /* @__PURE__ */ e("label", { className: "block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1", children: o("auth.forceChangePassword.confirmPassword", "Confirmer le nouveau mot de passe") }),
        /* @__PURE__ */ e(
          "input",
          {
            type: "password",
            required: !0,
            value: d,
            onChange: (r) => k(r.target.value),
            className: `w-full px-4 py-3 rounded-xl border ${d && d !== s ? "border-red-500 focus:ring-red-500" : "border-gray-300 dark:border-gray-600 focus:ring-blue-500"} bg-white dark:bg-gray-700 text-gray-900 dark:text-white focus:outline-none focus:ring-2`,
            placeholder: "Confirmez votre nouveau mot de passe"
          }
        ),
        d && d !== s && /* @__PURE__ */ e("p", { className: "mt-1 text-sm text-red-600", children: "Les mots de passe ne correspondent pas" })
      ] }),
      /* @__PURE__ */ e(
        "button",
        {
          type: "submit",
          disabled: !f || m,
          className: "w-full py-3 px-4 rounded-xl bg-blue-600 hover:bg-blue-700 text-white font-medium transition-colors disabled:opacity-50 disabled:cursor-not-allowed flex items-center justify-center gap-2",
          children: m ? /* @__PURE__ */ a(S, { children: [
            /* @__PURE__ */ e($, { className: "w-5 h-5 animate-spin" }),
            /* @__PURE__ */ e("span", { children: "Modification en cours..." })
          ] }) : /* @__PURE__ */ e("span", { children: o("auth.forceChangePassword.submit", "Définir mon nouveau mot de passe") })
        }
      )
    ] })
  ] }) }) });
}
export {
  H as ForceChangePasswordPage
};
//# sourceMappingURL=ForceChangePasswordPage-Bma4YttL.js.map
