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