import { defineComponent, h, reactive, ref } from 'vue';
import { buildFormInput, buildFormSubmit, PresetsBuildIn } from '@vue-layout/hyperscript';
import { a as useVuelidate, u as useToast } from './server.mjs';
import { required, minLength, maxLength } from '@vuelidate/validators';
import { u as useRoute, b as navigateTo, h as useNuxtApp } from './nuxt-link-5ac46069.mjs';
import { d as defineNuxtComponent, u as useAuthStore } from './auth-2d06b6ac.mjs';
import { b as buildAssetsURL } from './paths.mjs';
import 'ofetch';
import 'destr';
import '@unhead/vue';
import '@unhead/dom';
import '@unhead/ssr';
import './page-011b4897.mjs';
import 'vue-router';
import 'defu';
import 'unctx';
import 'h3';
import 'ufo';
import 'hapic';
import 'rapiq';
import '@vue-layout/basic';
import 'ilingo';
import 'nanoid';
import 'smob';
import 'browser-storage-adapter';
import 'cookie-es';
import 'ohash';
import 'vue/server-renderer';
import './composables-31566dd1.mjs';
import './_plugin-vue_export-helper-cc2b3d55.mjs';
import './config.mjs';
import 'scule';
import 'hookable';
import '@ucast/mongo2js';
import 'change-case';
import '@ebec/http';
import '@hapic/oauth2';

const Login$1 = "" + buildAssetsURL("Login.bb43092d.svg");
const Login = defineComponent({
  props: {
    width: {
      type: [Number, String],
      default: 750
    },
    height: {
      type: [Number, String],
      default: 500
    }
  },
  setup(props) {
    return () => h("img", {
      src: Login$1,
      width: props.width,
      height: props.height,
      style: {
        maxWidth: "100%"
      }
    });
  }
});

const useIlingo = () => {
  const nuxtApp = useNuxtApp();
  return nuxtApp.$ilingo;
};
const translateValidationMessage = (validator, parameters) => useIlingo().getSync(`validation.${validator}`, parameters, "en");
const login = defineNuxtComponent({
  setup() {
    const form = reactive({
      name: "",
      password: ""
    });
    const vuelidate = useVuelidate({
      name: {
        required,
        minLength: minLength(3),
        maxLength: maxLength(255)
      },
      password: {
        required,
        minLength: minLength(3),
        maxLength: maxLength(255)
      }
    }, form);
    const store = useAuthStore();
    const busy = ref(false);
    const submit = async () => {
      try {
        await store.login(form.name, form.password);
        const route = useRoute();
        const { redirect, ...query } = route.query;
        navigateTo({
          path: redirect || "/",
          query
        });
      } catch (e) {
        if (e instanceof Error) {
          const toast = useToast();
          toast.warning(e.message);
        }
      }
    };
    Promise.resolve().then(store.logout);
    const render = () => {
      const name = buildFormInput({
        validationResult: vuelidate.value.name,
        validationTranslator: translateValidationMessage,
        labelContent: "Name",
        value: form.name,
        onChange(value) {
          form.name = value;
        }
      });
      const password = buildFormInput({
        validationResult: vuelidate.value.password,
        validationTranslator: translateValidationMessage,
        labelContent: "Password",
        value: form.password,
        onChange(value) {
          form.password = value;
        },
        props: {
          type: "password"
        }
      });
      const submitButton = buildFormSubmit({
        validationResult: vuelidate.value,
        createText: "Login",
        createButtonClass: {
          value: "btn btn-sm btn-dark btn-block",
          presets: {
            [PresetsBuildIn.BOOTSTRAP_V5]: false
          }
        },
        createIconClass: "fa-solid fa-right-to-bracket",
        submit,
        busy
      });
      return h("div", { class: "container" }, [
        h("h4", [
          h("i", { class: "fa-solid fa-arrow-right-to-bracket pe-2" }),
          "Login"
        ]),
        h("div", {
          class: "text-center"
        }, [
          h(Login, {
            height: 320
          })
        ]),
        h("form", {
          onSubmit($event) {
            $event.preventDefault();
            return submit.call(null);
          }
        }, [
          name,
          password,
          submitButton
        ])
      ]);
    };
    return () => render();
  }
});

export { login as default };
//# sourceMappingURL=login-d09784bc.mjs.map
