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