import { defineComponent, computed, watch, createBlock, createCommentVNode, openBlock, unref } from "vue";
import { AuthSelector } from "@scalar/api-client/v2/blocks/scalar-auth-selector-block";
import { getSecurityRequirements, getSelectedSecurity } from "@scalar/api-client/v2/features/operation";
import { getDefaultSecurity } from "./helpers/get-default-security.js";
const _sfc_main = /* @__PURE__ */ defineComponent({
  __name: "Auth",
  props: {
    options: {},
    document: {},
    eventBus: {},
    securitySchemes: {},
    selectedServer: {},
    environment: {}
  },
  setup(__props) {
    const securityRequirements = computed(
      () => getSecurityRequirements(__props.document?.security)
    );
    const selectedSecurity = computed(
      () => getSelectedSecurity(
        __props.document?.["x-scalar-selected-security"],
        void 0,
        securityRequirements.value
      )
    );
    watch(
      () => __props.document?.["x-scalar-selected-security"],
      (documentSelectedSecurity) => {
        if (typeof documentSelectedSecurity !== "undefined") {
          return;
        }
        const defaultSecurity = getDefaultSecurity(
          securityRequirements.value,
          __props.options.authentication?.preferredSecurityScheme,
          __props.securitySchemes
        );
        if (!defaultSecurity) {
          return;
        }
        __props.eventBus.emit("auth:update:selected-security-schemes", {
          selectedRequirements: [defaultSecurity],
          newSchemes: [],
          meta: { type: "document" }
        });
      },
      { immediate: true }
    );
    return (_ctx, _cache) => {
      return Object.keys(_ctx.securitySchemes).length ? (openBlock(), createBlock(unref(AuthSelector), {
        key: 0,
        environment: _ctx.environment,
        eventBus: _ctx.eventBus,
        isReadOnly: "",
        isStatic: "",
        layout: "reference",
        meta: { type: "document" },
        persistAuth: _ctx.options.persistAuth,
        proxyUrl: _ctx.options.proxyUrl ?? "",
        securityRequirements: securityRequirements.value,
        securitySchemes: _ctx.securitySchemes,
        selectedSecurity: selectedSecurity.value,
        server: _ctx.selectedServer,
        title: "Authentication"
      }, null, 8, ["environment", "eventBus", "persistAuth", "proxyUrl", "securityRequirements", "securitySchemes", "selectedSecurity", "server"])) : createCommentVNode("", true);
    };
  }
});
export {
  _sfc_main as default
};
