import { defineComponent, ref, reactive, resolveComponent, openBlock, createElementBlock, createElementVNode, withModifiers, createVNode, unref, withCtx, toDisplayString } from "vue";
import { u as useI18n, j as useRouter, i as useRoute, k as useAuthService, D as DxForm_1, m as DxGroupItem_1, o as DxItem_1, g as DxLabel_1, p as DxRequiredRule_1, r as DxEmailRule_1, h as DxButtonItem_1, q as DxButtonOptions_1, n as notify } from "./index-67606569.mjs";
const _hoisted_1 = { class: "row justify-content-center mt-4" };
const _hoisted_2 = { class: "col-lg-5 col-md-5" };
const _hoisted_3 = { class: "card bg-secondary border-0 mb-0" };
const _hoisted_4 = { class: "card-body p-5" };
const _hoisted_5 = ["onSubmit"];
const _hoisted_6 = { class: "row mt-3" };
const _hoisted_7 = { class: "col-6 text-left" };
const _hoisted_8 = { class: "col-6 text-right" };
const _sfc_main = /* @__PURE__ */ defineComponent({
  __name: "VerifyEmail",
  setup(__props) {
    const { t } = useI18n();
    const router = useRouter();
    const route = useRoute();
    const form = ref(null);
    const isReady = ref(true);
    const hasUsername = !!route.query.username;
    const authService = useAuthService();
    const state = reactive({
      email: route.query.email
    });
    const onFormSubmit = async () => {
      isReady.value = false;
      try {
        const error = await authService.verifyEmail(route.query);
        if (error) {
          notify(t(`validation.${error.status}`), "error");
        } else {
          notify(t("message.emailConfirmedSuccesfully"));
          router.replace({
            name: "login",
            query: { username: state.email }
          });
        }
      } catch (error) {
        notify(error, "error");
      } finally {
        isReady.value = true;
      }
    };
    const onSendVerifyEmailLinkClick = async () => {
      const error = await authService.sendVerifyEmailLink(state.email);
      if (error) {
        notify(t(`validation.${error.status}`), "error");
      }
    };
    return (_ctx, _cache) => {
      const _component_router_link = resolveComponent("router-link");
      return openBlock(), createElementBlock("div", _hoisted_1, [
        createElementVNode("div", _hoisted_2, [
          createElementVNode("div", _hoisted_3, [
            createElementVNode("div", _hoisted_4, [
              createElementVNode("form", {
                novalidate: "",
                onSubmit: withModifiers(onFormSubmit, ["prevent"])
              }, [
                createVNode(unref(DxForm_1), {
                  ref_key: "form",
                  ref: form,
                  "label-location": "top",
                  "form-data": state
                }, {
                  default: withCtx(() => [
                    createVNode(unref(DxGroupItem_1), {
                      caption: unref(t)("emailVerification")
                    }, {
                      default: withCtx(() => [
                        createVNode(unref(DxItem_1), {
                          "data-field": "email",
                          "editor-type": "dxTextBox",
                          "editor-options": {
                            readOnly: hasUsername,
                            mode: "email"
                          }
                        }, {
                          default: withCtx(() => [
                            createVNode(unref(DxLabel_1), {
                              text: unref(t)("attributes.email")
                            }, null, 8, ["text"]),
                            createVNode(unref(DxRequiredRule_1)),
                            createVNode(unref(DxEmailRule_1))
                          ]),
                          _: 1
                        }, 8, ["editor-options"]),
                        createVNode(unref(DxButtonItem_1), { "horizontal-alignment": "center" }, {
                          default: withCtx(() => [
                            createVNode(unref(DxButtonOptions_1), {
                              type: "success",
                              text: unref(t)("confirm"),
                              "use-submit-behavior": true
                            }, null, 8, ["text"])
                          ]),
                          _: 1
                        })
                      ]),
                      _: 1
                    }, 8, ["caption"])
                  ]),
                  _: 1
                }, 8, ["form-data"])
              ], 40, _hoisted_5)
            ])
          ]),
          createElementVNode("div", _hoisted_6, [
            createElementVNode("div", _hoisted_7, [
              createVNode(_component_router_link, {
                class: "text-light",
                to: "/"
              }, {
                default: withCtx(() => [
                  createElementVNode("small", null, toDisplayString(unref(t)("haveAccount")), 1)
                ]),
                _: 1
              })
            ]),
            createElementVNode("div", _hoisted_8, [
              createElementVNode("a", {
                href: "#",
                class: "text-light",
                onClick: onSendVerifyEmailLinkClick
              }, [
                createElementVNode("small", null, toDisplayString(unref(t)("resendConfirmation")), 1)
              ])
            ])
          ])
        ])
      ]);
    };
  }
});
export {
  _sfc_main as default
};
