import { disposables as d } from "../../utils/disposables.js";
import { createStore as n } from "../../utils/store.js";
import { adjustScrollbarPadding as c } from "./adjust-scrollbar-padding.js";
import { handleIOSLocking as i } from "./handle-ios-locking.js";
import { preventScroll as f } from "./prevent-scroll.js";
function m(e) {
  let o = {};
  for (let t of e) Object.assign(o, t(o));
  return o;
}
let l = n(() => /* @__PURE__ */ new Map(), { PUSH(e, o) {
  var t;
  let r = (t = this.get(e)) != null ? t : { doc: e, count: 0, d: d(), meta: /* @__PURE__ */ new Set() };
  return r.count++, r.meta.add(o), this.set(e, r), this;
}, POP(e, o) {
  let t = this.get(e);
  return t && (t.count--, t.meta.delete(o)), this;
}, SCROLL_PREVENT({ doc: e, d: o, meta: t }) {
  let r = { doc: e, d: o, meta: m(t) }, a = [i(), c(), f()];
  a.forEach(({ before: s }) => s == null ? void 0 : s(r)), a.forEach(({ after: s }) => s == null ? void 0 : s(r));
}, SCROLL_ALLOW({ d: e }) {
  e.dispose();
}, TEARDOWN({ doc: e }) {
  this.delete(e);
} });
l.subscribe(() => {
  let e = l.getSnapshot(), o = /* @__PURE__ */ new Map();
  for (let [t] of e) o.set(t, t.documentElement.style.overflow);
  for (let t of e.values()) {
    let r = o.get(t.doc) === "hidden", a = t.count !== 0;
    (a && !r || !a && r) && l.dispatch(t.count > 0 ? "SCROLL_PREVENT" : "SCROLL_ALLOW", t), t.count === 0 && l.dispatch("TEARDOWN", t);
  }
});
export {
  l as overflows
};
