import { defineComponent, useId, createElementBlock, openBlock, Fragment, createElementVNode, createVNode, createBlock, createCommentVNode, normalizeClass, unref } from "vue";
import { ServerVariablesForm } from "@scalar/api-client/components/Server";
import { ScalarMarkdown } from "@scalar/components";
import _sfc_main$1 from "./Selector.vue.js";
const _hoisted_1 = ["id"];
const __default__ = {};
const _sfc_main = /* @__PURE__ */ defineComponent({
  ...__default__,
  __name: "ServerSelector",
  props: {
    eventBus: {},
    selectedServer: {},
    servers: {}
  },
  setup(__props) {
    const id = useId();
    const updateServer = (newServer) => {
      __props.eventBus.emit("server:update:selected", {
        url: __props.selectedServer?.url === newServer ? "" : newServer,
        meta: {
          type: "document"
        }
      });
    };
    const updateServerVariable = (key, value) => {
      const index = __props.servers.findIndex((s) => s.url === __props.selectedServer?.url);
      if (index === -1) {
        return;
      }
      __props.eventBus.emit("server:update:variables", {
        index,
        key,
        value,
        meta: {
          type: "document"
        }
      });
    };
    return (_ctx, _cache) => {
      return openBlock(), createElementBlock(Fragment, null, [
        _cache[0] || (_cache[0] = createElementVNode("label", { class: "bg-b-2 flex h-8 items-center rounded-t-xl border border-b-0 px-3 py-2.5 font-medium" }, " Server ", -1)),
        createElementVNode("div", {
          id: unref(id),
          class: normalizeClass(["border", {
            "rounded-b-xl": !__props.selectedServer?.description && !__props.selectedServer?.variables
          }])
        }, [
          __props.servers.length ? (openBlock(), createBlock(_sfc_main$1, {
            key: 0,
            selectedServer: __props.selectedServer,
            servers: __props.servers,
            target: unref(id),
            "onUpdate:modelValue": updateServer
          }, null, 8, ["selectedServer", "servers", "target"])) : createCommentVNode("", true)
        ], 10, _hoisted_1),
        createVNode(unref(ServerVariablesForm), {
          layout: "reference",
          variables: __props.selectedServer?.variables,
          "onUpdate:variable": updateServerVariable
        }, null, 8, ["variables"]),
        __props.selectedServer?.description ? (openBlock(), createBlock(unref(ScalarMarkdown), {
          key: 0,
          class: "text-c-3 rounded-b-xl border border-t-0 px-3 py-1.5",
          value: __props.selectedServer.description
        }, null, 8, ["value"])) : createCommentVNode("", true)
      ], 64);
    };
  }
});
export {
  _sfc_main as default
};
