import { h, ref, computed, resolveComponent } from 'vue';
import { b as useRuntimeConfig, d as buildVuelidateTranslator } from './server.mjs';
import { d as defineNuxtComponent } from './component.800bf414.mjs';
import { buildFormInput, SlotName, buildFormInputCheckbox } from '@vue-layout/hyperscript';
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 '@vuelidate/validators';
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.d2421f17.mjs';

const url = defineNuxtComponent({
  props: {
    entity: {
      type: Object,
      required: true
    }
  },
  emits: ["updated", "failed"],
  setup(props, { emit }) {
    if (!props.entity) {
      return () => h("div", []);
    }
    const scopes = ref([]);
    const redirectUri = ref("");
    const config = useRuntimeConfig();
    const generatedUrl = computed(() => {
      const link = new URL("authorize", config.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;
    });
    resolveComponent("ScopeList");
    const toggleScope = (scope) => {
      const index = scopes.value.indexOf(scope);
      if (index === -1) {
        scopes.value.push(scope);
      } else {
        scopes.value.splice(index, 1);
      }
    };
    const render = () => {
      const redirectUriInput = buildFormInput({
        labelContent: "Redirect URL",
        props: {
          placeholder: "..."
        },
        value: redirectUri
      });
      const generatedUrlInput = buildFormInput({
        labelContent: "Generated URL",
        props: {
          disabled: true
        },
        value: generatedUrl
      });
      const list2 = resolveComponent("ClientScopeList");
      return h("div", [
        h("h6", "URL Generator"),
        h("div", { class: "mb-1" }, [
          "Generate an authorize url by picking the scopes it needs to function."
        ]),
        h("hr"),
        h(list2, {
          withHeader: false,
          withSearch: false,
          query: {
            filter: {
              client_id: props.entity.id
            },
            relations: ["scope"]
          }
        }, {
          [SlotName.ITEM]: (props2) => buildFormInputCheckbox({
            validationTranslator: buildVuelidateTranslator(props2.translatorLocale),
            value: scopes.value.indexOf(props2.data.scope.name) !== -1,
            onChange(input) {
              toggleScope(props2.data.scope.name);
            },
            label: true,
            labelContent: props2.data.scope.name
          })
        }),
        h("hr"),
        redirectUriInput,
        h("hr"),
        generatedUrlInput
      ]);
    };
    return () => render();
  }
});

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