import { _ as _export_sfc, d as defineNuxtComponent, i as AClientScopes, j as useRuntimeConfig } from './server.mjs';
import { useSSRContext, ref, computed, resolveComponent, withCtx, createTextVNode, toDisplayString, createVNode } from 'vue';
import { VCFormInput, VCFormInputCheckbox } from '@vuecs/form-controls';
import { ssrRenderAttrs, ssrRenderComponent, ssrInterpolate } from 'vue/server-renderer';
import '../runtime.mjs';
import 'node:http';
import 'node:https';
import 'fs';
import 'path';
import 'node:fs';
import 'node:url';
import '../routes/renderer.mjs';
import 'vue-bundle-renderer/runtime';
import 'devalue';
import '@unhead/ssr';
import 'unhead';
import '@unhead/shared';
import 'vue-router';
import 'hapic';
import '@hapic/oauth2';
import 'rapiq';
import '@hapic/vault';
import '@vuecs/navigation';
import '@vuecs/list-controls/core';
import 'smob';
import '@vuecs/list-controls';
import 'ilingo';
import '@vuelidate/validators';
import '@vuelidate/core';
import 'nanoid';
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 _sfc_main = defineNuxtComponent({
  components: { VCFormInput, VCFormInputCheckbox, AClientScopes },
  props: {
    entity: {
      type: Object,
      required: true
    }
  },
  emits: ["updated", "failed"],
  setup(props, { emit }) {
    const scopes = ref([]);
    const redirectUri = ref("");
    const config = useRuntimeConfig();
    const generatedUrl = computed(() => {
      const link = new URL("authorize", config.public.publicUrl);
      link.searchParams.set("client_id", props.entity.id);
      if (scopes.value.length > 0) {
        link.searchParams.set("scope", encodeURIComponent(scopes.value.join(" ")));
      }
      if (redirectUri.value) {
        link.searchParams.set("redirect_uri", encodeURIComponent(redirectUri.value));
      }
      return link.href;
    });
    const toggleScope = (scope) => {
      const index = scopes.value.indexOf(scope);
      if (index === -1) {
        scopes.value.push(scope);
      } else {
        scopes.value.splice(index, 1);
      }
    };
    const query = {
      filter: {
        client_id: props.entity.id
      },
      relations: ["scope"]
    };
    return {
      toggleScope,
      query,
      redirectUri,
      generatedUrl,
      scopes
    };
  }
}, "$p4xkk2I3Jk");
function _sfc_ssrRender(_ctx, _push, _parent, _attrs, $props, $setup, $data, $options) {
  const _component_AClientScopes = resolveComponent("AClientScopes");
  const _component_VCFormGroup = resolveComponent("VCFormGroup");
  const _component_VCFormInputCheckbox = resolveComponent("VCFormInputCheckbox");
  const _component_VCFormInput = resolveComponent("VCFormInput");
  _push(`<div${ssrRenderAttrs(_attrs)}><h6>URL Generator</h6><div class="mb-1"> Generate an authorize url by picking the scopes it needs to function. </div><hr>`);
  _push(ssrRenderComponent(_component_AClientScopes, {
    header: false,
    query: _ctx.query,
    item: { class: "" }
  }, {
    item: withCtx((props, _push2, _parent2, _scopeId) => {
      if (_push2) {
        _push2(ssrRenderComponent(_component_VCFormGroup, {
          "validation-translator": props.translatorLocale
        }, {
          label: withCtx((_, _push3, _parent3, _scopeId2) => {
            if (_push3) {
              _push3(`${ssrInterpolate(props.data.scope.name)}`);
            } else {
              return [
                createTextVNode(toDisplayString(props.data.scope.name), 1)
              ];
            }
          }),
          default: withCtx((_, _push3, _parent3, _scopeId2) => {
            if (_push3) {
              _push3(ssrRenderComponent(_component_VCFormInputCheckbox, {
                "model-value": _ctx.scopes.indexOf(props.data.scope.name) !== -1,
                "onUpdate:modelValue": ($event) => _ctx.toggleScope(props.data.scope.name)
              }, null, _parent3, _scopeId2));
            } else {
              return [
                createVNode(_component_VCFormInputCheckbox, {
                  "model-value": _ctx.scopes.indexOf(props.data.scope.name) !== -1,
                  "onUpdate:modelValue": ($event) => _ctx.toggleScope(props.data.scope.name)
                }, null, 8, ["model-value", "onUpdate:modelValue"])
              ];
            }
          }),
          _: 2
        }, _parent2, _scopeId));
      } else {
        return [
          createVNode(_component_VCFormGroup, {
            "validation-translator": props.translatorLocale
          }, {
            label: withCtx(() => [
              createTextVNode(toDisplayString(props.data.scope.name), 1)
            ]),
            default: withCtx(() => [
              createVNode(_component_VCFormInputCheckbox, {
                "model-value": _ctx.scopes.indexOf(props.data.scope.name) !== -1,
                "onUpdate:modelValue": ($event) => _ctx.toggleScope(props.data.scope.name)
              }, null, 8, ["model-value", "onUpdate:modelValue"])
            ]),
            _: 2
          }, 1032, ["validation-translator"])
        ];
      }
    }),
    _: 1
  }, _parent));
  _push(`<hr>`);
  _push(ssrRenderComponent(_component_VCFormGroup, null, {
    label: withCtx((_, _push2, _parent2, _scopeId) => {
      if (_push2) {
        _push2(` Redirect URL `);
      } else {
        return [
          createTextVNode(" Redirect URL ")
        ];
      }
    }),
    default: withCtx((_, _push2, _parent2, _scopeId) => {
      if (_push2) {
        _push2(ssrRenderComponent(_component_VCFormInput, {
          modelValue: _ctx.redirectUri,
          "onUpdate:modelValue": ($event) => _ctx.redirectUri = $event,
          placeholder: "..."
        }, null, _parent2, _scopeId));
      } else {
        return [
          createVNode(_component_VCFormInput, {
            modelValue: _ctx.redirectUri,
            "onUpdate:modelValue": ($event) => _ctx.redirectUri = $event,
            placeholder: "..."
          }, null, 8, ["modelValue", "onUpdate:modelValue"])
        ];
      }
    }),
    _: 1
  }, _parent));
  _push(`<hr>`);
  _push(ssrRenderComponent(_component_VCFormGroup, null, {
    label: withCtx((_, _push2, _parent2, _scopeId) => {
      if (_push2) {
        _push2(` Generated URL `);
      } else {
        return [
          createTextVNode(" Generated URL ")
        ];
      }
    }),
    default: withCtx((_, _push2, _parent2, _scopeId) => {
      if (_push2) {
        _push2(ssrRenderComponent(_component_VCFormInput, {
          modelValue: _ctx.generatedUrl,
          "onUpdate:modelValue": ($event) => _ctx.generatedUrl = $event,
          disabled: true
        }, null, _parent2, _scopeId));
      } else {
        return [
          createVNode(_component_VCFormInput, {
            modelValue: _ctx.generatedUrl,
            "onUpdate:modelValue": ($event) => _ctx.generatedUrl = $event,
            disabled: true
          }, null, 8, ["modelValue", "onUpdate:modelValue"])
        ];
      }
    }),
    _: 1
  }, _parent));
  _push(`</div>`);
}
const _sfc_setup = _sfc_main.setup;
_sfc_main.setup = (props, ctx) => {
  const ssrContext = useSSRContext();
  (ssrContext.modules || (ssrContext.modules = /* @__PURE__ */ new Set())).add("pages/admin/clients/[id]/url.vue");
  return _sfc_setup ? _sfc_setup(props, ctx) : void 0;
};
const url = /* @__PURE__ */ _export_sfc(_sfc_main, [["ssrRender", _sfc_ssrRender]]);

export { url as default };
//# sourceMappingURL=url-VppY8KgO.mjs.map
