import { defineComponent as w, ref as m, toRef as R, provide as T, shallowRef as $, onServerPrefetch as A, onMounted as B, watch as d, computed as N, createElementBlock as P, openBlock as D, Fragment as F, createBlock as I, createCommentVNode as U, createVNode as C, unref as r, resolveDynamicComponent as W, withCtx as n, createTextVNode as L, toDisplayString as O, renderSlot as p, isRef as Y } from "vue";
import { parseJsonOrYaml as _, redirectToProxy as j } from "@scalar/oas-utils/helpers";
import { useColorMode as J } from "@scalar/use-hooks/useColorMode";
import { useSeoMeta as q } from "@unhead/vue";
import { useFavicon as z } from "@vueuse/core";
import G from "../components/ApiReferenceLayout.vue.js";
import { NAV_STATE_SYMBOL as H } from "../hooks/useNavState.js";
import { useMultipleDocuments as K } from "../features/multiple-documents/useMultipleDocuments.js";
import { onCustomEvent as h } from "./events/listeners.js";
import Q from "../features/multiple-documents/DocumentSelector.vue.js";
const se = /* @__PURE__ */ w({
  __name: "ApiReferenceWorkspace",
  props: {
    configuration: {},
    getWorkspaceStore: { type: Function }
  },
  setup(M) {
    const f = M, {
      availableDocuments: u,
      selectedConfiguration: t,
      selectedDocumentIndex: l,
      isIntersectionEnabled: x,
      hash: y,
      hashPrefix: S
    } = K({
      configuration: R(f, "configuration"),
      isIntersectionEnabled: m(!1),
      hash: m(""),
      hashPrefix: m("")
    }), g = (e, o) => fetch(
      j(t.value.proxyUrl, e.toString()),
      o
    );
    T(H, { isIntersectionEnabled: x, hash: y, hashPrefix: S });
    const v = $(null), a = f.getWorkspaceStore(), i = u, s = (e) => {
      if (a.workspace.documents[e.slug ?? "default"] === void 0) {
        if (e.content) {
          const o = typeof e.content == "string" ? _(e.content) : e.content;
          return a.addDocumentSync({
            name: e.slug ?? "default",
            document: typeof o == "function" ? o() : o
          });
        }
        if (e.url)
          return a.addDocument({
            name: e.slug ?? "default",
            url: e.url,
            fetch: g
          });
      }
    };
    i.value.forEach((e) => {
      e.content && s(e);
    }), A(() => {
      i.value.forEach((e) => {
        e.url && s(e);
      });
    }), B(() => {
      i.value.forEach((e) => {
        e.url && s(e);
      });
    }), h(v, "scalar-update-dark-mode", (e) => {
      a.update("x-scalar-dark-mode", e.data.value);
    }), h(v, "scalar-update-active-document", (e) => {
      a.update("x-scalar-active-document", e.data.value);
    });
    const { toggleColorMode: E, isDarkMode: V } = J({
      initialColorMode: t.value.darkMode ? "dark" : void 0,
      overrideColorMode: t.value.forceDarkModeState
    });
    d(
      () => t.value.darkMode,
      (e) => a.update("x-scalar-dark-mode", !!e)
    ), d(
      () => V.value,
      (e) => a.update("x-scalar-dark-mode", e),
      { immediate: !0 }
    ), d(
      () => l.value,
      (e) => {
        var o;
        return a.update(
          "x-scalar-active-document",
          (o = u.value[e]) == null ? void 0 : o.slug
        );
      },
      { immediate: !0 }
    ), d(
      () => u.value,
      (e) => {
        e.forEach(s);
      }
    ), t.value.metaData && q(t.value.metaData);
    const b = N(() => t.value.favicon);
    return z(b), (e, o) => {
      var k;
      return D(), P(F, null, [
        (k = r(t)) != null && k.customCss ? (D(), I(W("style"), { key: 0 }, {
          default: n(() => [
            L(O(r(t).customCss), 1)
          ]),
          _: 1
        })) : U("", !0),
        C(G, {
          configuration: r(t),
          isDark: !!r(a).workspace["x-scalar-dark-mode"],
          onToggleDarkMode: o[1] || (o[1] = () => r(E)()),
          onUpdateContent: o[2] || (o[2] = (c) => e.$emit("updateContent", c))
        }, {
          footer: n(() => [
            p(e.$slots, "footer")
          ]),
          "content-end": n(() => [
            p(e.$slots, "footer")
          ]),
          "document-selector": n(() => [
            C(r(Q), {
              modelValue: r(l),
              "onUpdate:modelValue": o[0] || (o[0] = (c) => Y(l) ? l.value = c : null),
              options: r(u)
            }, null, 8, ["modelValue", "options"])
          ]),
          "sidebar-start": n(() => [
            p(e.$slots, "sidebar-start")
          ]),
          _: 3
        }, 8, ["configuration", "isDark"])
      ], 64);
    };
  }
});
export {
  se as default
};
