import { jsx as e, jsxs as t } from "react/jsx-runtime";
import { useState as i, useEffect as C } from "react";
import { useTranslation as _ } from "react-i18next";
import { useSearchParams as R, Link as x } from "react-router-dom";
import { Loader2 as y, CheckCircle2 as N, XCircle as k, Mail as M, RefreshCw as S } from "lucide-react";
import { T as D, d as E } from "./index-CeEMms9z.js";
function X() {
  const { t: r } = _("auth"), [w] = R(), c = w.get("token"), [a, n] = i("loading"), [f, o] = i(""), [g, P] = i(""), [m, T] = i(""), [u, h] = i(!1), [p, d] = i("");
  C(() => {
    if (!c) {
      n("error"), o(r("confirmEmailPage.invalidTokenMessage"));
      return;
    }
    (async () => {
      try {
        const s = await E.confirmEmail(c);
        n("success"), o(s.message), P(s.email);
      } catch (s) {
        const v = s, b = s?.code;
        n(b === "TOKEN_EXPIRED" ? "expired" : b === "TOKEN_ALREADY_USED" ? "already_used" : "error"), o(v?.message || r("confirmEmailPage.errorMessage"));
      }
    })();
  }, [c, r]);
  const j = async (l) => {
    if (l.preventDefault(), !!m) {
      h(!0), d("");
      try {
        const s = await E.resendConfirmation(m);
        d(s.message);
      } catch (s) {
        d(s?.message || r("common:error"));
      } finally {
        h(!1);
      }
    }
  };
  return /* @__PURE__ */ e("div", { className: "min-h-screen flex items-center justify-center bg-[var(--bg-primary)] 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(D, {}) }),
    /* @__PURE__ */ t("div", { className: "bg-[var(--bg-secondary)] rounded-2xl shadow-xl p-8", children: [
      a === "loading" && /* @__PURE__ */ t("div", { className: "text-center", children: [
        /* @__PURE__ */ e(y, { className: "w-16 h-16 text-[var(--info-text)] animate-spin mx-auto mb-4" }),
        /* @__PURE__ */ e("h2", { className: "text-xl font-semibold text-[var(--text-primary)] mb-2", children: r("confirmEmailPage.loadingTitle") }),
        /* @__PURE__ */ e("p", { className: "text-[var(--text-secondary)]", children: r("confirmEmailPage.loadingMessage") })
      ] }),
      a === "success" && /* @__PURE__ */ t("div", { className: "text-center", children: [
        /* @__PURE__ */ e("div", { className: "w-16 h-16 bg-[var(--success-bg)] rounded-full flex items-center justify-center mx-auto mb-4", children: /* @__PURE__ */ e(N, { className: "w-10 h-10 text-[var(--success-text)]" }) }),
        /* @__PURE__ */ e("h2", { className: "text-xl font-semibold text-[var(--text-primary)] mb-2", children: r("confirmEmailPage.successTitle") }),
        /* @__PURE__ */ e("p", { className: "text-[var(--text-secondary)] mb-6", children: f }),
        g && /* @__PURE__ */ t("p", { className: "text-sm text-[var(--text-tertiary)] mb-6", children: [
          r("confirmEmailPage.account"),
          " ",
          /* @__PURE__ */ e("strong", { children: g })
        ] }),
        /* @__PURE__ */ e(
          x,
          {
            to: "/login",
            className: "inline-flex items-center justify-center gap-2 px-6 py-3 bg-[var(--color-accent-600)] text-white rounded-lg font-medium hover:opacity-90 transition-all",
            children: r("confirmEmailPage.signIn")
          }
        )
      ] }),
      (a === "error" || a === "expired" || a === "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 ${a === "already_used" ? "bg-[var(--warning-bg)]" : "bg-[var(--error-bg)]"}`, children: a === "already_used" ? /* @__PURE__ */ e(N, { className: "w-10 h-10 text-[var(--warning-text)]" }) : /* @__PURE__ */ e(k, { className: "w-10 h-10 text-[var(--error-text)]" }) }),
        /* @__PURE__ */ t("h2", { className: "text-xl font-semibold text-[var(--text-primary)] mb-2", children: [
          a === "expired" && r("confirmEmailPage.expiredTitle"),
          a === "already_used" && r("confirmEmailPage.alreadyUsedTitle"),
          a === "error" && r("confirmEmailPage.errorTitle")
        ] }),
        /* @__PURE__ */ e("p", { className: "text-[var(--text-secondary)] mb-6", children: f }),
        (a === "expired" || a === "error") && /* @__PURE__ */ t("div", { className: "border-t border-[var(--border-color)] pt-6 mt-6", children: [
          /* @__PURE__ */ e("p", { className: "text-sm text-[var(--text-secondary)] mb-4", children: r("confirmEmailPage.resendConfirmation") }),
          /* @__PURE__ */ t("form", { onSubmit: j, 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(M, { className: "h-5 w-5 text-[var(--text-tertiary)]" }) }),
              /* @__PURE__ */ e(
                "input",
                {
                  type: "email",
                  value: m,
                  onChange: (l) => T(l.target.value),
                  placeholder: r("confirmEmailPage.emailPlaceholder"),
                  className: "block w-full pl-10 pr-3 py-2.5 border border-[var(--border-color)] rounded-lg bg-[var(--bg-card)] text-[var(--text-primary)] placeholder-[var(--text-tertiary)] focus:ring-2 focus:ring-[var(--info-border)] focus:border-transparent",
                  required: !0
                }
              )
            ] }),
            /* @__PURE__ */ t(
              "button",
              {
                type: "submit",
                disabled: u,
                className: "w-full flex items-center justify-center gap-2 px-4 py-2.5 bg-[var(--color-accent-600)] text-white rounded-lg font-medium hover:opacity-90 disabled:opacity-50 transition-colors",
                children: [
                  u ? /* @__PURE__ */ e(y, { className: "w-5 h-5 animate-spin" }) : /* @__PURE__ */ e(S, { className: "w-5 h-5" }),
                  r("confirmEmailPage.resendButton")
                ]
              }
            )
          ] }),
          p && /* @__PURE__ */ e("p", { className: "mt-3 text-sm text-[var(--success-text)]", children: p })
        ] }),
        a === "already_used" && /* @__PURE__ */ e(
          x,
          {
            to: "/login",
            className: "inline-flex items-center justify-center gap-2 px-6 py-3 bg-[var(--color-accent-600)] text-white rounded-lg font-medium hover:opacity-90 transition-all",
            children: r("confirmEmailPage.signIn")
          }
        )
      ] })
    ] }),
    /* @__PURE__ */ e("p", { className: "text-center text-sm text-[var(--text-tertiary)] mt-6", children: /* @__PURE__ */ e(x, { to: "/login", className: "hover:underline", children: r("confirmEmailPage.backToLogin") }) })
  ] }) });
}
export {
  X as ConfirmEmailPage
};
//# sourceMappingURL=ConfirmEmailPage-BK43SLul.js.map
