import { reactive, ref, h } from 'vue';
import { buildFormInput, buildFormSubmit, PresetsBuildIn } from '@vue-layout/hyperscript';
import { f as useVuelidate, d as useAuthStore, a as useRoute, n as navigateTo, b as useToast, u as useNuxtApp } from './server.mjs';
import { required, minLength, maxLength } from '@vuelidate/validators';
import { d as defineNuxtComponent } from './component.ed786e27.mjs';
import Login from './LoginSVG.34e49c14.mjs';
import 'ofetch';
import 'hookable';
import 'unctx';
import 'destr';
import 'ufo';
import 'h3';
import '@unhead/vue';
import '@unhead/dom';
import 'vue-router';
import '@ebec/http';
import 'hapic';
import 'rapiq';
import '@vue-layout/basic';
import 'change-case';
import '@ucast/mongo2js';
import '@hapic/oauth2';
import 'ilingo';
import 'nanoid';
import 'smob';
import 'browser-storage-adapter';
import 'cookie-es';
import 'ohash';
import 'vue/server-renderer';
import 'defu';
import './node-server.mjs';
import 'node-fetch-native/polyfill';
import 'http';
import 'https';
import 'unenv/runtime/fetch/index';
import 'scule';
import 'unstorage';
import 'radix3';
import 'node:fs';
import 'node:url';
import 'pathe';
import './composables.c25fc8b8.mjs';

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();
        navigateTo({ path: route.query.redirect || "/" });
      } catch (e) {
        const toast = useToast();
        toast.warning(e.message);
      }
    };
    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.3d319667.mjs.map
