import { reactive as b, ref as p, computed as S } from "vue";
import { scrollToId as l } from "@scalar/helpers/dom/scroll-to-id";
import { measure as g } from "@scalar/helpers/testing/measure";
import { traverseDocument as v } from "../../traverse-schema/helpers/traverse-document.js";
import { lazyBus as O } from "../../../components/Lazy/lazyBus.js";
const z = (a, o) => {
  const r = b({}), i = p(!1), m = (e) => r[e] = !r[e], c = (e, t) => r[e] = t, n = (e, t) => {
    const s = o.getSectionId(e);
    if (s && s !== e)
      if (r[s])
        l(e, t);
      else {
        const d = O.on((f) => {
          f.loaded === e && (l(e, t), d());
        });
        c(s, !0);
      }
  }, u = S(() => {
    const e = g("traverse-document", () => v(a.value, o));
    return o.config.value.defaultOpenAllTags && e.entries.forEach((t) => c(t.id, !0)), e;
  });
  return {
    collapsedSidebarItems: r,
    isSidebarOpen: i,
    items: u,
    scrollToOperation: n,
    setCollapsedSidebarItem: c,
    toggleCollapsedSidebarItem: m
  };
};
export {
  z as createSidebar
};
