import { b as buildAssetsURL } from '../../handlers/renderer.mjs';
import { _ as _export_sfc, d as defineNuxtComponent, a as APagination, k as ASearch, l as ATitle, B as AIdentityProviders, a0 as AIdentityProviderIcon, I as ARealms, a1 as injectAPIClient, i as useAuthStore, a2 as useValidationTranslator, R as REALM_MASTER_NAME, g as useRoute, n as navigateTo, f as useRuntimeConfig } from '../server.mjs';
import { defineComponent, h, useSSRContext, reactive, ref, toRef, watch, resolveComponent, mergeProps, withCtx, createTextVNode, createVNode, openBlock, createBlock, Fragment, renderList, toDisplayString, computed } from 'vue';
import { isClientError } from '@hapic/oauth2';
import { u as useToast } from './toast-FRA3c5ua.mjs';
import useVuelidate from '@vuelidate/core';
import { required, minLength, maxLength } from '@vuelidate/validators';
import { ssrRenderAttrs, ssrRenderComponent, ssrRenderList, ssrRenderAttr, ssrInterpolate } from 'vue/server-renderer';
import 'vue-bundle-renderer/runtime';
import '../../nitro/node-server.mjs';
import 'node:http';
import 'node:https';
import 'fs';
import 'path';
import 'node:fs';
import 'node:url';
import 'devalue';
import '@unhead/ssr';
import 'unhead';
import '@unhead/shared';
import 'vue-router';
import '@ebec/http/core';
import 'hapic';
import 'rapiq';
import '@hapic/vault';
import '@vuecs/navigation';
import 'change-case';
import '@vuecs/list-controls/core';
import 'smob';
import '@vuecs/list-controls';
import 'ilingo';
import 'nanoid';
import '@vuecs/form-controls';
import '@vuecs/pagination';
import '@ucast/mongo2js';
import 'bootstrap-vue-next';
import '@vuecs/preset-bootstrap-v5';
import '@vuecs/preset-font-awesome';
import '@vuecs/countdown';
import '@vuecs/timeago';
import '@vuecs/form-controls/core';
import 'browser-storage-adapter';

const __nuxt_component_0 = defineNuxtComponent({
  props: {
    listRef: {
      type: Object
    },
    entity: {
      type: Object,
      required: true
    },
    modelValue: {
      type: String
    }
  },
  emits: ["update:modelValue"],
  setup(props, { emit }) {
    const modelValue = toRef(props, "modelValue");
    const isMaster = computed(() => props.entity.name === REALM_MASTER_NAME);
    const canCheck = computed(() => !(isMaster.value && !modelValue.value) && modelValue.value !== props.entity.id);
    return () => {
      if (canCheck.value) {
        return h("button", {
          class: {
            "btn btn-xs btn-primary": canCheck.value,
            "btn btn-xs btn-danger": !canCheck.value
          },
          onClick($event) {
            $event.preventDefault();
            emit("update:modelValue", props.entity.id);
          }
        }, [
          h("i", {
            class: {
              "fa fa-check": canCheck.value,
              "fa fa-times": !canCheck.value
            }
          })
        ]);
      }
      return h("button", { class: "btn btn-xs btn-disabled btn-success", disabled: true }, [
        h("i", {
          class: "fa-solid fa-check"
        })
      ]);
    };
  }
}, "$BvqHu6TDsR");
const Login = "" + buildAssetsURL("Login.lAurmWky.svg");
const LoginSVG = defineComponent({
  props: {
    width: {
      type: [Number, String],
      default: 750
    },
    height: {
      type: [Number, String],
      default: 500
    }
  },
  setup(props) {
    return () => h("img", {
      src: Login,
      width: props.width,
      height: props.height,
      style: {
        maxWidth: "100%"
      }
    });
  }
});
const _sfc_main = defineNuxtComponent({
  components: {
    APagination,
    ASearch,
    ATitle,
    LoginSVG,
    AIdentityProviders,
    AIdentityProviderIcon,
    ARealms,
    RealmSelectAction: __nuxt_component_0
  },
  setup() {
    const apiClient = injectAPIClient();
    const toast = useToast();
    const form = reactive({
      name: "",
      password: "",
      realm_id: ""
    });
    const vuelidate = useVuelidate({
      name: {
        required,
        minLength: minLength(3),
        maxLength: maxLength(255)
      },
      password: {
        required,
        minLength: minLength(3),
        maxLength: maxLength(255)
      },
      realm_id: {}
    }, form);
    const store = useAuthStore();
    const runtimeConfig = useRuntimeConfig();
    const busy = ref(false);
    const realmId = toRef(form, "realm_id");
    const identityProviderQuery = {
      filters: {
        realm_id: realmId.value || ""
      }
    };
    const identityProviderRef = ref(null);
    watch(realmId, async (val, oldVal) => {
      if (val !== oldVal) {
        if (identityProviderRef.value) {
          identityProviderQuery.filters.realm_id = realmId.value;
          identityProviderRef.value.load();
        }
      }
    });
    const submit = async () => {
      try {
        await store.login({
          name: form.name,
          password: form.password,
          realmId: form.realm_id
        });
        const route = useRoute();
        const { redirect, ...query } = route.query;
        navigateTo({
          path: redirect || "/",
          query
        });
      } catch (e) {
        if (isClientError(e) && toast) {
          toast.show({ variant: "warning", body: e.message });
        }
      }
    };
    Promise.resolve().then(store.logout);
    const buildIdentityProviderURL = (id) => apiClient.identityProvider.getAuthorizeUri(
      runtimeConfig.public.apiUrl,
      id
    );
    return {
      vuelidate,
      translator: useValidationTranslator(),
      form,
      submit,
      busy,
      identityProviderQuery,
      identityProviderRef,
      buildIdentityProviderURL
    };
  }
}, "$V4hxAv6YfE");
function _sfc_ssrRender(_ctx, _push, _parent, _attrs, $props, $setup, $data, $options) {
  const _component_LoginSVG = resolveComponent("LoginSVG");
  const _component_VCFormGroup = resolveComponent("VCFormGroup");
  const _component_VCFormInput = resolveComponent("VCFormInput");
  const _component_VCFormSubmit = resolveComponent("VCFormSubmit");
  const _component_AIdentityProviders = resolveComponent("AIdentityProviders");
  const _component_APagination = resolveComponent("APagination");
  const _component_AIdentityProviderIcon = resolveComponent("AIdentityProviderIcon");
  const _component_ARealms = resolveComponent("ARealms");
  const _component_ATitle = resolveComponent("ATitle");
  const _component_ASearch = resolveComponent("ASearch");
  const _component_RealmSelectAction = __nuxt_component_0;
  _push(`<div${ssrRenderAttrs(mergeProps({ class: "container" }, _attrs))} data-v-03b701f5><h4 data-v-03b701f5><i class="fa-solid fa-arrow-right-to-bracket pe-2" data-v-03b701f5></i> Login </h4><div class="text-center" data-v-03b701f5>`);
  _push(ssrRenderComponent(_component_LoginSVG, { height: 320 }, null, _parent));
  _push(`</div><form data-v-03b701f5><div class="row" data-v-03b701f5><div class="col-8" data-v-03b701f5>`);
  _push(ssrRenderComponent(_component_VCFormGroup, {
    "validation-result": _ctx.vuelidate.name,
    "validation-translator": _ctx.translator
  }, {
    label: withCtx((_, _push2, _parent2, _scopeId) => {
      if (_push2) {
        _push2(` Name `);
      } else {
        return [
          createTextVNode(" Name ")
        ];
      }
    }),
    default: withCtx((_, _push2, _parent2, _scopeId) => {
      if (_push2) {
        _push2(ssrRenderComponent(_component_VCFormInput, {
          modelValue: _ctx.form.name,
          "onUpdate:modelValue": ($event) => _ctx.form.name = $event
        }, null, _parent2, _scopeId));
      } else {
        return [
          createVNode(_component_VCFormInput, {
            modelValue: _ctx.form.name,
            "onUpdate:modelValue": ($event) => _ctx.form.name = $event
          }, null, 8, ["modelValue", "onUpdate:modelValue"])
        ];
      }
    }),
    _: 1
  }, _parent));
  _push(ssrRenderComponent(_component_VCFormGroup, {
    "validation-result": _ctx.vuelidate.password,
    "validation-translator": _ctx.translator
  }, {
    label: withCtx((_, _push2, _parent2, _scopeId) => {
      if (_push2) {
        _push2(` Password `);
      } else {
        return [
          createTextVNode(" Password ")
        ];
      }
    }),
    default: withCtx((_, _push2, _parent2, _scopeId) => {
      if (_push2) {
        _push2(ssrRenderComponent(_component_VCFormInput, {
          modelValue: _ctx.form.password,
          "onUpdate:modelValue": ($event) => _ctx.form.password = $event,
          type: "password"
        }, null, _parent2, _scopeId));
      } else {
        return [
          createVNode(_component_VCFormInput, {
            modelValue: _ctx.form.password,
            "onUpdate:modelValue": ($event) => _ctx.form.password = $event,
            type: "password"
          }, null, 8, ["modelValue", "onUpdate:modelValue"])
        ];
      }
    }),
    _: 1
  }, _parent));
  _push(ssrRenderComponent(_component_VCFormSubmit, {
    modelValue: _ctx.busy,
    "onUpdate:modelValue": ($event) => _ctx.busy = $event,
    "validation-result": _ctx.vuelidate,
    "create-text": "Login",
    "create-button-class": { value: "btn btn-sm btn-dark btn-block", presets: { bootstrap: false } },
    "create-icon-class": "fa-solid fa-right-to-bracket",
    submit: _ctx.submit
  }, null, _parent));
  _push(`<hr data-v-03b701f5>`);
  _push(ssrRenderComponent(_component_AIdentityProviders, {
    ref: "identityProviderRef",
    query: _ctx.identityProviderQuery,
    footer: false
  }, {
    footer: withCtx((props, _push2, _parent2, _scopeId) => {
      if (_push2) {
        _push2(ssrRenderComponent(_component_APagination, {
          busy: props.busy,
          meta: props.meta,
          load: props.load,
          total: props.total
        }, null, _parent2, _scopeId));
      } else {
        return [
          createVNode(_component_APagination, {
            busy: props.busy,
            meta: props.meta,
            load: props.load,
            total: props.total
          }, null, 8, ["busy", "meta", "load", "total"])
        ];
      }
    }),
    body: withCtx((props, _push2, _parent2, _scopeId) => {
      if (_push2) {
        _push2(`<div class="d-flex flex-row" data-v-03b701f5${_scopeId}><!--[-->`);
        ssrRenderList(props.data, (item, key) => {
          _push2(`<div data-v-03b701f5${_scopeId}><a${ssrRenderAttr("href", _ctx.buildIdentityProviderURL(item.id))} class="btn btn-dark btn-xs p-2 me-1 identity-provider-box bg-dark" data-v-03b701f5${_scopeId}><div class="d-flex flex-column" data-v-03b701f5${_scopeId}><div class="text-center mb-1" data-v-03b701f5${_scopeId}>`);
          _push2(ssrRenderComponent(_component_AIdentityProviderIcon, {
            class: "fa-2x",
            entity: item
          }, null, _parent2, _scopeId));
          _push2(`</div><div data-v-03b701f5${_scopeId}>${ssrInterpolate(item.name)}</div></div></a></div>`);
        });
        _push2(`<!--]--></div>`);
      } else {
        return [
          createVNode("div", { class: "d-flex flex-row" }, [
            (openBlock(true), createBlock(Fragment, null, renderList(props.data, (item, key) => {
              return openBlock(), createBlock("div", { key }, [
                createVNode("a", {
                  href: _ctx.buildIdentityProviderURL(item.id),
                  class: "btn btn-dark btn-xs p-2 me-1 identity-provider-box bg-dark"
                }, [
                  createVNode("div", { class: "d-flex flex-column" }, [
                    createVNode("div", { class: "text-center mb-1" }, [
                      createVNode(_component_AIdentityProviderIcon, {
                        class: "fa-2x",
                        entity: item
                      }, null, 8, ["entity"])
                    ]),
                    createVNode("div", null, toDisplayString(item.name), 1)
                  ])
                ], 8, ["href"])
              ]);
            }), 128))
          ])
        ];
      }
    }),
    _: 1
  }, _parent));
  _push(`</div><div class="col-4" data-v-03b701f5>`);
  _push(ssrRenderComponent(_component_ARealms, null, {
    header: withCtx((props, _push2, _parent2, _scopeId) => {
      if (_push2) {
        _push2(ssrRenderComponent(_component_ATitle, null, null, _parent2, _scopeId));
        _push2(ssrRenderComponent(_component_ASearch, {
          load: props.load,
          busy: props.busy
        }, null, _parent2, _scopeId));
      } else {
        return [
          createVNode(_component_ATitle),
          createVNode(_component_ASearch, {
            load: props.load,
            busy: props.busy
          }, null, 8, ["load", "busy"])
        ];
      }
    }),
    footer: withCtx((props, _push2, _parent2, _scopeId) => {
      if (_push2) {
        _push2(ssrRenderComponent(_component_APagination, {
          busy: props.busy,
          meta: props.meta,
          load: props.load,
          total: props.total
        }, null, _parent2, _scopeId));
      } else {
        return [
          createVNode(_component_APagination, {
            busy: props.busy,
            meta: props.meta,
            load: props.load,
            total: props.total
          }, null, 8, ["busy", "meta", "load", "total"])
        ];
      }
    }),
    itemActions: withCtx((props, _push2, _parent2, _scopeId) => {
      if (_push2) {
        _push2(ssrRenderComponent(_component_RealmSelectAction, {
          modelValue: _ctx.form.realm_id,
          "onUpdate:modelValue": ($event) => _ctx.form.realm_id = $event,
          "list-ref": _ctx.identityProviderRef,
          entity: props.data
        }, null, _parent2, _scopeId));
      } else {
        return [
          createVNode(_component_RealmSelectAction, {
            modelValue: _ctx.form.realm_id,
            "onUpdate:modelValue": ($event) => _ctx.form.realm_id = $event,
            "list-ref": _ctx.identityProviderRef,
            entity: props.data
          }, null, 8, ["modelValue", "onUpdate:modelValue", "list-ref", "entity"])
        ];
      }
    }),
    _: 1
  }, _parent));
  _push(`</div></div></form></div>`);
}
const _sfc_setup = _sfc_main.setup;
_sfc_main.setup = (props, ctx) => {
  const ssrContext = useSSRContext();
  (ssrContext.modules || (ssrContext.modules = /* @__PURE__ */ new Set())).add("pages/login.vue");
  return _sfc_setup ? _sfc_setup(props, ctx) : void 0;
};
const login = /* @__PURE__ */ _export_sfc(_sfc_main, [["ssrRender", _sfc_ssrRender], ["__scopeId", "data-v-03b701f5"]]);

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