import { QSpace } from './QSpace-afce9c3e.js';
import { QForm, DefaultAuthLayout, AlignCenterMiddleWrap, LogoNameBox, _sfc_main as _sfc_main$a, QPage } from './QForm-3da35848.js';
import { _sfc_main as _sfc_main$8 } from './AuthTextField-df802034.js';
import { useLoginStore, computed, openBlock, createBlock, unref, isRef, onMounted, ref, resolveComponent, createElementBlock, createVNode, withCtx, createTextVNode, toDisplayString, Fragment, createBaseVNode, useAuthStore, useRouter, useQuasar, renderSlot, onUnmounted } from './__federation_expose_Modules-a9c6a6fc.js';
import { idRules, passwordRules } from './validationUtil-531209ab.js';
import { _sfc_main as _sfc_main$9 } from './AuthBtn-d1b681f3.js';
import { QCheckbox } from './QCheckbox-5e45c1d5.js';
import { _export_sfc } from './_plugin-vue_export-helper-e9a2c33e.js';

const _sfc_main$7 = {
  __name: 'LoginIdInput',
  setup(__props) {
    const loginStore = useLoginStore();
    const id = computed({
      get: () => loginStore.id,
      set: v => loginStore.setId(v)
    });
    return (_ctx, _cache) => {
      return openBlock(), createBlock(_sfc_main$8, {
        modelValue: unref(id),
        "onUpdate:modelValue": _cache[0] || (_cache[0] = $event => isRef(id) ? id.value = $event : null),
        label: "ID",
        rules: unref(idRules)
      }, null, 8, ["modelValue", "rules"]);
    };
  }
};

const _sfc_main$6 = {
  __name: 'LoginPasswordInput',
  setup(__props) {
    const loginStore = useLoginStore();
    const password = computed({
      get: () => loginStore.password,
      set: value => loginStore.setPassword(value)
    });
    onMounted(() => {
      loginStore.setPassword('');
    });
    return (_ctx, _cache) => {
      return openBlock(), createBlock(_sfc_main$8, {
        modelValue: unref(password),
        "onUpdate:modelValue": _cache[0] || (_cache[0] = $event => isRef(password) ? password.value = $event : null),
        label: "Password",
        type: "password",
        rules: unref(passwordRules)
      }, null, 8, ["modelValue", "rules"]);
    };
  }
};

const _sfc_main$5 = {
  __name: 'LoginButton',
  setup(__props) {
    return (_ctx, _cache) => {
      return openBlock(), createBlock(_sfc_main$9, {
        label: "Login",
        color: "primary",
        type: "submit"
      });
    };
  }
};

const RememberMeCheckbox_vue_vue_type_style_index_0_scoped_b3b34bee_lang = '';

const _sfc_main$4 = {
  __name: 'RememberMeCheckbox',
  setup(__props) {
    const loginStore = useLoginStore();
    const title = ref("Remember me");
    const checked = computed({
      get: () => loginStore.rememberMe,
      set: v => loginStore.setRememberMe(v)
    });
    return (_ctx, _cache) => {
      return openBlock(), createBlock(QCheckbox, {
        modelValue: unref(checked),
        "onUpdate:modelValue": _cache[0] || (_cache[0] = $event => isRef(checked) ? checked.value = $event : null),
        label: title.value,
        color: "primary",
        dense: ""
      }, null, 8, ["modelValue", "label"]);
    };
  }
};
const RememberMeCheckbox = /*#__PURE__*/_export_sfc(_sfc_main$4, [['__scopeId', "data-v-b3b34bee"]]);

const _hoisted_1$2 = /*#__PURE__*/createBaseVNode("span", {
  class: "q-mx-xs"
}, " / ", -1);
const _sfc_main$3 = {
  __name: 'ForgetIdPasswordLink',
  setup(__props) {
    const id_title = ref("Forgot ID");
    const password_title = ref("Forgot password");
    return (_ctx, _cache) => {
      const _component_router_link = resolveComponent("router-link");
      return openBlock(), createElementBlock(Fragment, null, [createVNode(_component_router_link, {
        to: "/forgot-id",
        class: "text-grey-9"
      }, {
        default: withCtx(() => [createTextVNode(toDisplayString(id_title.value), 1)]),
        _: 1
      }), _hoisted_1$2, createVNode(_component_router_link, {
        to: "/forgot-password",
        class: "text-grey-9"
      }, {
        default: withCtx(() => [createTextVNode(toDisplayString(password_title.value), 1)]),
        _: 1
      })], 64);
    };
  }
};

const _hoisted_1$1 = {
  class: "text-center text-grey-6"
};
const _sfc_main$2 = {
  __name: 'SignupLink',
  setup(__props) {
    const link = ref("Sign up");
    return (_ctx, _cache) => {
      const _component_router_link = resolveComponent("router-link");
      return openBlock(), createElementBlock("div", _hoisted_1$1, [createTextVNode(" Don't have an account "), createVNode(_component_router_link, {
        class: "text-grey-9",
        to: "/signup"
      }, {
        default: withCtx(() => [createTextVNode(toDisplayString(link.value), 1)]),
        _: 1
      })]);
    };
  }
};

const _sfc_main$1 = {
  __name: 'LoginForm',
  setup(__props) {
    const authStore = useAuthStore();
    const router = useRouter();
    const $q = useQuasar();
    const onSubmit = () => {
      $q.loading.show();
      authStore.login().then(() => {
        router.push({
          name: 'Home'
        });
      }).catch(error => {
        console.log(error);
        if (error.response.status === 401) {
          $q.notify({
            type: 'negative',
            message: 'Invalid id or password'
          });
          return;
        } else if (error.response.status === 500) {
          $q.notify({
            type: 'warning',
            message: error.response.data.error
          });
          return;
        }
        $q.notify({
          type: 'negative',
          message: 'Login failed if this error persists please contact support'
        });
        return;
      }).finally(() => {
        $q.loading.hide();
      });
    };
    return (_ctx, _cache) => {
      return openBlock(), createBlock(QForm, {
        class: "auth-input-form q-mx-auto",
        onSubmit: onSubmit
      }, {
        default: withCtx(() => [renderSlot(_ctx.$slots, "default")]),
        _: 3
      });
    };
  }
};

const LoginPage_vue_vue_type_style_index_0_scoped_c244d9b0_lang = '';

const _hoisted_1 = {
  class: "row"
};
const _sfc_main = {
  __name: 'LoginPage',
  setup(__props) {
    const loginStore = useLoginStore();
    loginStore.reset();
    onUnmounted(() => {
      loginStore.reset();
    });
    return (_ctx, _cache) => {
      return openBlock(), createBlock(DefaultAuthLayout, null, {
        default: withCtx(() => [createVNode(QPage, {
          id: "d1__loginPage",
          class: "flex"
        }, {
          default: withCtx(() => [createVNode(AlignCenterMiddleWrap, null, {
            default: withCtx(() => [createVNode(LogoNameBox), createVNode(QSpace, {
              class: "q-py-md q-mt-xs"
            }), createVNode(_sfc_main$a), createVNode(QSpace, {
              class: "q-py-md q-mt-xs"
            }), createVNode(_sfc_main$1, null, {
              default: withCtx(() => [createVNode(_sfc_main$7), createVNode(_sfc_main$6), createVNode(_sfc_main$5)]),
              _: 1
            }), createVNode(QSpace, {
              class: "q-pt-md q-pb-xs"
            }), createBaseVNode("div", _hoisted_1, [createVNode(RememberMeCheckbox), createVNode(QSpace), createVNode(_sfc_main$3)]), createVNode(QSpace, {
              class: "q-py-md q-mt-xs"
            }), createVNode(_sfc_main$2)]),
            _: 1
          })]),
          _: 1
        })]),
        _: 1
      });
    };
  }
};
const LoginPage = /*#__PURE__*/_export_sfc(_sfc_main, [['__scopeId', "data-v-c244d9b0"]]);

export { LoginPage as default };
