import { jsx as e, jsxs as t, Fragment as w } from "react/jsx-runtime";
import { useState as r, useEffect as A } from "react";
import { useSearchParams as I, useNavigate as R, Link as g } from "react-router-dom";
import { XCircle as N, CheckCircle2 as _, Lock as x, AlertCircle as T, EyeOff as v, Eye as k, Loader2 as F } from "lucide-react";
import { T as O, a as K } from "./index-Dh9kUeDn.js";
function Y() {
  const [C] = I(), P = R(), l = C.get("token"), [n, j] = r(""), [b, L] = r(""), [c, E] = r(!1), [m, S] = r(!1), [i, f] = r(!1), [o, u] = r("form"), [d, a] = r(null);
  A(() => {
    l || (u("invalid_token"), a("Lien de réinitialisation invalide. Aucun token fourni."));
  }, [l]);
  const D = () => n.length < 8 ? (a("Le mot de passe doit contenir au moins 8 caractères"), !1) : n !== b ? (a("Les mots de passe ne correspondent pas"), !1) : !0;
  return /* @__PURE__ */ e("div", { className: "min-h-screen flex items-center justify-center bg-gray-50 dark:bg-gray-900 p-8", children: /* @__PURE__ */ t("div", { className: "w-full max-w-md", children: [
    /* @__PURE__ */ e("div", { className: "flex justify-end mb-8", children: /* @__PURE__ */ e(O, {}) }),
    /* @__PURE__ */ t("div", { className: "bg-white dark:bg-gray-800 rounded-2xl shadow-xl p-8", children: [
      o === "invalid_token" && /* @__PURE__ */ t("div", { className: "text-center", children: [
        /* @__PURE__ */ e("div", { className: "w-16 h-16 bg-red-100 dark:bg-red-900/30 rounded-full flex items-center justify-center mx-auto mb-4", children: /* @__PURE__ */ e(N, { className: "w-10 h-10 text-red-600 dark:text-red-400" }) }),
        /* @__PURE__ */ e("h2", { className: "text-xl font-semibold text-gray-900 dark:text-white mb-2", children: "Lien invalide" }),
        /* @__PURE__ */ e("p", { className: "text-gray-600 dark:text-gray-400 mb-6", children: d }),
        /* @__PURE__ */ e(
          g,
          {
            to: "/forgot-password",
            className: "inline-flex items-center justify-center gap-2 px-6 py-3 bg-blue-600 text-white rounded-lg font-medium hover:bg-blue-700 transition-colors",
            children: "Demander un nouveau lien"
          }
        )
      ] }),
      o === "error" && /* @__PURE__ */ t("div", { className: "text-center", children: [
        /* @__PURE__ */ e("div", { className: "w-16 h-16 bg-red-100 dark:bg-red-900/30 rounded-full flex items-center justify-center mx-auto mb-4", children: /* @__PURE__ */ e(N, { className: "w-10 h-10 text-red-600 dark:text-red-400" }) }),
        /* @__PURE__ */ e("h2", { className: "text-xl font-semibold text-gray-900 dark:text-white mb-2", children: "Lien expiré" }),
        /* @__PURE__ */ e("p", { className: "text-gray-600 dark:text-gray-400 mb-6", children: d }),
        /* @__PURE__ */ e(
          g,
          {
            to: "/forgot-password",
            className: "inline-flex items-center justify-center gap-2 px-6 py-3 bg-blue-600 text-white rounded-lg font-medium hover:bg-blue-700 transition-colors",
            children: "Demander un nouveau lien"
          }
        )
      ] }),
      o === "success" && /* @__PURE__ */ t("div", { className: "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(_, { className: "w-10 h-10 text-green-600 dark:text-green-400" }) }),
        /* @__PURE__ */ e("h2", { className: "text-xl font-semibold text-gray-900 dark:text-white mb-2", children: "Mot de passe réinitialisé !" }),
        /* @__PURE__ */ e("p", { className: "text-gray-600 dark:text-gray-400 mb-6", children: "Votre mot de passe a été modifié avec succès. Vous pouvez maintenant vous connecter." }),
        /* @__PURE__ */ e(
          "button",
          {
            onClick: () => P("/login"),
            className: "inline-flex items-center justify-center gap-2 px-6 py-3 bg-gradient-to-r from-blue-600 to-purple-600 text-white rounded-lg font-medium hover:from-blue-700 hover:to-purple-700 transition-all",
            children: "Se connecter"
          }
        )
      ] }),
      o === "form" && /* @__PURE__ */ t(w, { children: [
        /* @__PURE__ */ t("div", { className: "text-center mb-8", children: [
          /* @__PURE__ */ e("div", { className: "w-16 h-16 bg-blue-100 dark:bg-blue-900/30 rounded-full flex items-center justify-center mx-auto mb-4", children: /* @__PURE__ */ e(x, { className: "w-8 h-8 text-blue-600 dark:text-blue-400" }) }),
          /* @__PURE__ */ e("h2", { className: "text-2xl font-bold text-gray-900 dark:text-white mb-2", children: "Nouveau mot de passe" }),
          /* @__PURE__ */ e("p", { className: "text-gray-600 dark:text-gray-400", children: "Choisissez un nouveau mot de passe sécurisé." })
        ] }),
        d && /* @__PURE__ */ t("div", { className: "mb-6 p-4 bg-red-500/10 border border-red-500/20 rounded-lg flex items-start gap-3", children: [
          /* @__PURE__ */ e(T, { className: "w-5 h-5 text-red-500 flex-shrink-0 mt-0.5" }),
          /* @__PURE__ */ e("p", { className: "text-sm text-red-500", children: d })
        ] }),
        /* @__PURE__ */ t("form", { onSubmit: async (s) => {
          if (s.preventDefault(), a(null), !(!D() || !l)) {
            f(!0);
            try {
              await K.resetPassword(l, n), u("success");
            } catch (p) {
              const y = p, h = p?.code;
              h === "TOKEN_EXPIRED" || h === "TOKEN_ALREADY_USED" || h === "INVALID_TOKEN" ? (u("error"), a(y?.message || "Le lien de réinitialisation est invalide ou a expiré.")) : a(y?.message || "Une erreur est survenue");
            } finally {
              f(!1);
            }
          }
        }, className: "space-y-4", children: [
          /* @__PURE__ */ t("div", { children: [
            /* @__PURE__ */ e("label", { htmlFor: "password", className: "block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2", children: "Nouveau mot de passe" }),
            /* @__PURE__ */ t("div", { className: "relative", children: [
              /* @__PURE__ */ e("div", { className: "absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-none", children: /* @__PURE__ */ e(x, { className: "h-5 w-5 text-gray-400" }) }),
              /* @__PURE__ */ e(
                "input",
                {
                  id: "password",
                  type: c ? "text" : "password",
                  value: n,
                  onChange: (s) => j(s.target.value),
                  className: "block w-full pl-10 pr-10 py-2.5 border border-gray-300 dark:border-gray-600 rounded-lg bg-white dark:bg-gray-700 text-gray-900 dark:text-white placeholder-gray-400 focus:ring-2 focus:ring-blue-500 focus:border-transparent",
                  placeholder: "••••••••",
                  required: !0,
                  autoComplete: "new-password",
                  disabled: i
                }
              ),
              /* @__PURE__ */ e(
                "button",
                {
                  type: "button",
                  onClick: () => E(!c),
                  className: "absolute inset-y-0 right-0 pr-3 flex items-center text-gray-400 hover:text-gray-600",
                  tabIndex: -1,
                  children: c ? /* @__PURE__ */ e(v, { className: "h-5 w-5" }) : /* @__PURE__ */ e(k, { className: "h-5 w-5" })
                }
              )
            ] }),
            /* @__PURE__ */ e("p", { className: "mt-1 text-xs text-gray-500 dark:text-gray-400", children: "Minimum 8 caractères" })
          ] }),
          /* @__PURE__ */ t("div", { children: [
            /* @__PURE__ */ e("label", { htmlFor: "confirmPassword", className: "block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2", children: "Confirmer le mot de passe" }),
            /* @__PURE__ */ t("div", { className: "relative", children: [
              /* @__PURE__ */ e("div", { className: "absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-none", children: /* @__PURE__ */ e(x, { className: "h-5 w-5 text-gray-400" }) }),
              /* @__PURE__ */ e(
                "input",
                {
                  id: "confirmPassword",
                  type: m ? "text" : "password",
                  value: b,
                  onChange: (s) => L(s.target.value),
                  className: "block w-full pl-10 pr-10 py-2.5 border border-gray-300 dark:border-gray-600 rounded-lg bg-white dark:bg-gray-700 text-gray-900 dark:text-white placeholder-gray-400 focus:ring-2 focus:ring-blue-500 focus:border-transparent",
                  placeholder: "••••••••",
                  required: !0,
                  autoComplete: "new-password",
                  disabled: i
                }
              ),
              /* @__PURE__ */ e(
                "button",
                {
                  type: "button",
                  onClick: () => S(!m),
                  className: "absolute inset-y-0 right-0 pr-3 flex items-center text-gray-400 hover:text-gray-600",
                  tabIndex: -1,
                  children: m ? /* @__PURE__ */ e(v, { className: "h-5 w-5" }) : /* @__PURE__ */ e(k, { className: "h-5 w-5" })
                }
              )
            ] })
          ] }),
          /* @__PURE__ */ e(
            "button",
            {
              type: "submit",
              disabled: i,
              className: "w-full flex items-center justify-center gap-2 px-4 py-3 bg-gradient-to-r from-blue-600 to-purple-600 text-white rounded-lg font-medium hover:from-blue-700 hover:to-purple-700 disabled:opacity-50 transition-all",
              children: i ? /* @__PURE__ */ t(w, { children: [
                /* @__PURE__ */ e(F, { className: "h-5 w-5 animate-spin" }),
                "Réinitialisation..."
              ] }) : "Réinitialiser le mot de passe"
            }
          )
        ] })
      ] }),
      /* @__PURE__ */ e("div", { className: "mt-6 pt-6 border-t border-gray-200 dark:border-gray-700", children: /* @__PURE__ */ e(
        g,
        {
          to: "/login",
          className: "flex items-center justify-center text-sm text-gray-600 dark:text-gray-400 hover:text-blue-600 dark:hover:text-blue-400 transition-colors",
          children: "Retour à la connexion"
        }
      ) })
    ] })
  ] }) });
}
export {
  Y as ResetPasswordPage
};
//# sourceMappingURL=ResetPasswordPage-h1eK19v5.js.map
