import { defineComponent as I, computed as s, ref as y, createElementBlock as _, createCommentVNode as k, unref as m, openBlock as z, createVNode as L } from "vue";
import { useWorkspace as O, useActiveEntities as T } from "@scalar/api-client/store";
import { freezeAtTop as B } from "@scalar/helpers/dom/freeze-at-top";
import { getSlugUid as N } from "@scalar/oas-utils/transforms";
import { getCurrentIndex as U } from "./get-current-index.js";
import { lazyBus as b, hasLazyLoaded as d } from "../../Lazy/lazyBus.js";
import { useNavState as x } from "../../../hooks/useNavState.js";
import A from "./TraversedEntry.vue.js";
import { useSidebar as V } from "../../../features/sidebar/hooks/useSidebar.js";
const w = { key: 0 }, K = /* @__PURE__ */ I({
  __name: "TraversedEntryContainer",
  props: {
    document: {},
    config: {},
    clientOptions: {},
    store: {}
  },
  emits: ["allEntriesLoaded"],
  setup(c, { emit: f }) {
    const p = f, { collections: g, servers: l } = O(), { activeCollection: C } = T(), t = s(() => {
      var e;
      if ((e = c.config) != null && e.slug) {
        const o = g[N(c.config.slug)];
        if (o)
          return o;
      }
      return C.value;
    }), S = s(() => {
      if (t.value) {
        if (t.value.selectedServerUid) {
          const e = l[t.value.selectedServerUid];
          if (e)
            return e;
        }
        return l[t.value.servers[0]];
      }
    }), { items: r } = V(), { hash: a, isIntersectionEnabled: h } = x(), n = B(a.value), u = () => {
      n == null || n(), d.value = !0, h.value = !0;
    }, i = y(/* @__PURE__ */ new Set()), E = s(
      () => U(a.value, r.value.entries)
    );
    return b.on(({ loading: e, loaded: o, save: v }) => {
      d.value || (e && v && i.value.add(e), o && v && i.value.delete(o), i.value.size === 0 && (p("allEntriesLoaded", !0), setTimeout(() => u(), 300)));
    }), setTimeout(() => u(), 5e3), (e, o) => m(r).entries.length && t.value ? (z(), _("div", w, [
      L(A, {
        entries: m(r).entries,
        activeCollection: t.value,
        activeServer: S.value,
        clientOptions: e.clientOptions,
        config: e.config,
        document: e.document,
        rootIndex: E.value,
        store: e.store
      }, null, 8, ["entries", "activeCollection", "activeServer", "clientOptions", "config", "document", "rootIndex", "store"])
    ])) : k("", !0);
  }
});
export {
  K as default
};
