import { jsx as e, jsxs as t } from "react/jsx-runtime";
import { useState as s, useEffect as C } from "react";
import { useSearchParams as R, Link as m } from "react-router-dom";
import { Loader2 as y, CheckCircle2 as N, XCircle as j, Mail as _, RefreshCw as S } from "lucide-react";
import { T as L, c as v } from "./index-CwSaRXXg.js";
function I() {
  const [k] = R(), l = k.get("token"), [r, n] = s("loading"), [u, o] = s(""), [g, w] = s(""), [d, E] = s(""), [x, h] = s(!1), [f, c] = s("");
  return C(() => {
    if (!l) {
      n("error"), o("Lien de confirmation invalide. Aucun token fourni.");
      return;
    }
    (async () => {
      try {
        const a = await v.confirmEmail(l);
        n("success"), o(a.message), w(a.email);
      } catch (a) {
        const p = a, b = a?.code;
        n(b === "TOKEN_EXPIRED" ? "expired" : b === "TOKEN_ALREADY_USED" ? "already_used" : "error"), o(p?.message || "Une erreur est survenue lors de la confirmation.");
      }
    })();
  }, [l]), /* @__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(L, {}) }),
    /* @__PURE__ */ t("div", { className: "bg-white dark:bg-gray-800 rounded-2xl shadow-xl p-8", children: [
      r === "loading" && /* @__PURE__ */ t("div", { className: "text-center", children: [
        /* @__PURE__ */ e(y, { className: "w-16 h-16 text-blue-500 animate-spin mx-auto mb-4" }),
        /* @__PURE__ */ e("h2", { className: "text-xl font-semibold text-gray-900 dark:text-white mb-2", children: "Confirmation en cours..." }),
        /* @__PURE__ */ e("p", { className: "text-gray-600 dark:text-gray-400", children: "Veuillez patienter pendant que nous vérifions votre email." })
      ] }),
      r === "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(N, { 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: "Email confirmé !" }),
        /* @__PURE__ */ e("p", { className: "text-gray-600 dark:text-gray-400 mb-6", children: u }),
        g && /* @__PURE__ */ t("p", { className: "text-sm text-gray-500 dark:text-gray-400 mb-6", children: [
          "Compte : ",
          /* @__PURE__ */ e("strong", { children: g })
        ] }),
        /* @__PURE__ */ e(
          m,
          {
            to: "/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"
          }
        )
      ] }),
      (r === "error" || r === "expired" || r === "already_used") && /* @__PURE__ */ t("div", { className: "text-center", children: [
        /* @__PURE__ */ e("div", { className: `w-16 h-16 rounded-full flex items-center justify-center mx-auto mb-4 ${r === "already_used" ? "bg-amber-100 dark:bg-amber-900/30" : "bg-red-100 dark:bg-red-900/30"}`, children: r === "already_used" ? /* @__PURE__ */ e(N, { className: "w-10 h-10 text-amber-600 dark:text-amber-400" }) : /* @__PURE__ */ e(j, { className: "w-10 h-10 text-red-600 dark:text-red-400" }) }),
        /* @__PURE__ */ t("h2", { className: "text-xl font-semibold text-gray-900 dark:text-white mb-2", children: [
          r === "expired" && "Lien expiré",
          r === "already_used" && "Lien déjà utilisé",
          r === "error" && "Erreur de confirmation"
        ] }),
        /* @__PURE__ */ e("p", { className: "text-gray-600 dark:text-gray-400 mb-6", children: u }),
        (r === "expired" || r === "error") && /* @__PURE__ */ t("div", { className: "border-t border-gray-200 dark:border-gray-700 pt-6 mt-6", children: [
          /* @__PURE__ */ e("p", { className: "text-sm text-gray-600 dark:text-gray-400 mb-4", children: "Demander un nouveau lien de confirmation :" }),
          /* @__PURE__ */ t("form", { onSubmit: async (i) => {
            if (i.preventDefault(), !!d) {
              h(!0), c("");
              try {
                const a = await v.resendConfirmation(d);
                c(a.message);
              } catch (a) {
                c(a?.message || "Erreur lors de l'envoi.");
              } finally {
                h(!1);
              }
            }
          }, className: "space-y-3", children: [
            /* @__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(_, { className: "h-5 w-5 text-gray-400" }) }),
              /* @__PURE__ */ e(
                "input",
                {
                  type: "email",
                  value: d,
                  onChange: (i) => E(i.target.value),
                  placeholder: "Votre email",
                  className: "block w-full pl-10 pr-3 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",
                  required: !0
                }
              )
            ] }),
            /* @__PURE__ */ t(
              "button",
              {
                type: "submit",
                disabled: x,
                className: "w-full flex items-center justify-center gap-2 px-4 py-2.5 bg-blue-600 text-white rounded-lg font-medium hover:bg-blue-700 disabled:opacity-50 transition-colors",
                children: [
                  x ? /* @__PURE__ */ e(y, { className: "w-5 h-5 animate-spin" }) : /* @__PURE__ */ e(S, { className: "w-5 h-5" }),
                  "Renvoyer le lien"
                ]
              }
            )
          ] }),
          f && /* @__PURE__ */ e("p", { className: "mt-3 text-sm text-green-600 dark:text-green-400", children: f })
        ] }),
        r === "already_used" && /* @__PURE__ */ e(
          m,
          {
            to: "/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"
          }
        )
      ] })
    ] }),
    /* @__PURE__ */ e("p", { className: "text-center text-sm text-gray-500 dark:text-gray-400 mt-6", children: /* @__PURE__ */ e(m, { to: "/login", className: "hover:underline", children: "Retour à la connexion" }) })
  ] }) });
}
export {
  I as ConfirmEmailPage
};
//# sourceMappingURL=ConfirmEmailPage-Buj4x-rx.js.map
