import { freezeAtTop as v } from "@scalar/helpers/dom/freeze-at-top";
import { ref as z } from "vue";
import { hasLazyLoaded as t, lazyBus as T } from "../components/Lazy/lazyBus.js";
import { useNavState as p } from "./useNavState.js";
const d = 25, h = 500, y = () => {
  const { hash: i, isIntersectionEnabled: l } = p(), e = z(/* @__PURE__ */ new Set()), c = t.value ? "" : i.value, f = v(c), m = () => {
    f?.(), t.value = !0, l.value = !0;
  };
  T.on(({ loading: o, loaded: s, save: n }) => {
    if (!t.value && (o && n && e.value.add(o), s && n && e.value.delete(s), e.value.size === 0)) {
      let r = Date.now();
      const u = () => {
        const a = Date.now();
        if (e.value.size === 0) {
          if (a - r >= h) {
            m();
            return;
          }
        } else
          r = a;
        setTimeout(u, d);
      };
      u();
    }
  });
};
export {
  y as useFreezing
};
