import { defineComponent as b, ref as S, watch as k, unref as r, openBlock as a, createElementBlock as v, createElementVNode as l, Fragment as g, renderList as I, toDisplayString as V, createCommentVNode as d, createVNode as p, createBlock as y, pushScopeId as B, popScopeId as w } from "vue";
import { useServerStore as C, findVariables as E } from "@scalar/api-client";
import { ScalarIcon as N, ScalarMarkdown as x } from "@scalar/components";
import D from "./ServerItem.vue.js";
import L from "./ServerVariables.vue.js";
const U = (c) => (B("data-v-2bf97807"), c = c(), w(), c), j = { key: 0 }, F = /* @__PURE__ */ U(() => /* @__PURE__ */ l("span", { class: "scalar-card-serverlist-title" }, "Base URL", -1)), M = { class: "scalar-card-serverlist" }, O = { class: "scalar-card-serverlist-container" }, R = { class: "server-item" }, q = { class: "server-selector" }, z = ["value"], A = ["value"], G = {
  key: 0,
  muted: ""
}, H = { class: "description" }, W = /* @__PURE__ */ b({
  __name: "BaseUrl",
  setup(c) {
    const { server: e, setServer: h } = C(), s = S(0);
    return k(
      [s, () => e.servers],
      () => {
        var n, _, m;
        if (!e.servers.length) return;
        const o = ((n = e.servers[s.value]) == null ? void 0 : n.variables) ?? {}, i = o ? Object.keys(o).map((t) => {
          var f;
          return {
            name: t,
            value: ((f = o[t].default) == null ? void 0 : f.toString()) ?? ""
          };
        }) : [];
        E(
          (_ = e.servers[s.value]) == null ? void 0 : _.url
        ).filter((t) => !o[t]).forEach((t) => {
          i.push({
            name: t,
            value: ""
          });
        }), h({
          selectedServer: s.value,
          description: (m = e.servers[s.value]) == null ? void 0 : m.description,
          variables: i
        });
      },
      {
        immediate: !0,
        deep: !0
      }
    ), (o, i) => r(e).servers.length > 0 ? (a(), v("div", j, [
      F,
      l("div", M, [
        l("div", O, [
          l("div", R, [
            l("div", q, [
              r(e).servers.length > 1 ? (a(), v("select", {
                key: 0,
                value: s.value,
                onInput: i[0] || (i[0] = (u) => s.value = parseInt(
                  u.target.value,
                  10
                ))
              }, [
                (a(!0), v(g, null, I(r(e).servers, (u, n) => (a(), v("option", {
                  key: n,
                  value: n
                }, V(u.url), 9, A))), 128))
              ], 40, z)) : d("", !0),
              p(D, {
                value: r(e).servers[s.value],
                variables: r(e).variables
              }, null, 8, ["value", "variables"]),
              r(e).servers.length > 1 ? (a(), y(r(N), {
                key: 1,
                icon: "ChevronDown"
              })) : d("", !0)
            ])
          ]),
          p(L, {
            value: r(e).variables
          }, null, 8, ["value"])
        ])
      ]),
      r(e).description ? (a(), v("div", G, [
        l("div", H, [
          p(r(x), {
            value: r(e).description
          }, null, 8, ["value"])
        ])
      ])) : d("", !0)
    ])) : d("", !0);
  }
});
export {
  W as default
};
