import { _ as _export_sfc, d as defineNuxtComponent, b as ClientScopeList, e as useRuntimeConfig } from '../server.mjs';
import { useSSRContext, ref, computed, resolveComponent, withCtx, createVNode } from 'vue';
import { FormInput, FormInputCheckbox } from '@vue-layout/form-controls';
import { ssrRenderAttrs, ssrRenderComponent } from 'vue/server-renderer';
import 'ofetch';
import 'hookable';
import 'unctx';
import 'vue-router';
import 'h3';
import 'ufo';
import '@ebec/http';
import 'hapic';
import '@hapic/oauth2';
import 'rapiq';
import '@hapic/vault';
import '@vue-layout/navigation';
import 'destr';
import 'change-case';
import '@vue-layout/list-controls/core';
import 'smob';
import '@vue-layout/list-controls';
import '@vue-layout/pagination';
import '@ucast/mongo2js';
import '@vuelidate/validators';
import 'ilingo';
import '@vuelidate/core';
import 'nanoid';
import '@unhead/ssr';
import 'unhead';
import '@unhead/shared';
import 'bootstrap-vue-next';
import '@vue-layout/preset-bootstrap-v5';
import '@vue-layout/preset-font-awesome';
import '@vue-layout/countdown';
import '@vue-layout/timeago';
import 'browser-storage-adapter';
import 'cookie-es';
import 'ohash';
import 'defu';
import '../../nitro/node-server.mjs';
import 'node-fetch-native/polyfill';
import 'node:http';
import 'node:https';
import 'unenv/runtime/fetch/index';
import 'scule';
import 'klona';
import 'unstorage';
import 'radix3';
import 'node:fs';
import 'node:url';
import 'pathe';
import 'http-graceful-shutdown';

const _sfc_main = /* @__PURE__ */ defineNuxtComponent({
  components: { FormInput, FormInputCheckbox, ClientScopeList },
  props: {
    entity: {
      type: Object,
      required: true
    }
  },
  emits: ["updated", "failed"],
  setup(props, { emit }) {
    const scopes = ref([]);
    const redirectUri = ref("");
    const config = /* @__PURE__ */ 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_ClientScopeList = resolveComponent("ClientScopeList");
  const _component_FormInputCheckbox = resolveComponent("FormInputCheckbox");
  const _component_FormInput = resolveComponent("FormInput");
  _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_ClientScopeList, {
    "header-title": false,
    "header-search": false,
    query: _ctx.query,
    item: { class: "" }
  }, {
    item: withCtx((props, _push2, _parent2, _scopeId) => {
      if (_push2) {
        _push2(ssrRenderComponent(_component_FormInputCheckbox, {
          "validation-translator": props.translatorLocale,
          "model-value": _ctx.scopes.indexOf(props.data.scope.name) !== -1,
          label: true,
          "label-content": props.data.scope.name,
          "onUpdate:modelValue": ($event) => _ctx.toggleScope(props.data.scope.name)
        }, null, _parent2, _scopeId));
      } else {
        return [
          createVNode(_component_FormInputCheckbox, {
            "validation-translator": props.translatorLocale,
            "model-value": _ctx.scopes.indexOf(props.data.scope.name) !== -1,
            label: true,
            "label-content": props.data.scope.name,
            "onUpdate:modelValue": ($event) => _ctx.toggleScope(props.data.scope.name)
          }, null, 8, ["validation-translator", "model-value", "label-content", "onUpdate:modelValue"])
        ];
      }
    }),
    _: 1
  }, _parent));
  _push(`<hr>`);
  _push(ssrRenderComponent(_component_FormInput, {
    modelValue: _ctx.redirectUri,
    "onUpdate:modelValue": ($event) => _ctx.redirectUri = $event,
    "label-content": "Redirect URL",
    label: true,
    placeholder: "..."
  }, null, _parent));
  _push(`<hr>`);
  _push(ssrRenderComponent(_component_FormInput, {
    modelValue: _ctx.generatedUrl,
    "onUpdate:modelValue": ($event) => _ctx.generatedUrl = $event,
    "label-content": "Generated URL",
    label: true,
    disabled: true
  }, null, _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-32160d73.mjs.map
