import { computed, watchEffect } from 'vue';
import getScrollBarSize from '../_util/getScrollBarSize.mjs';
import { updateCSS, removeCSS } from '../vc-util/Dom/dynamicCSS.mjs';

const UNIQUE_ID = `vc-util-locker-${Date.now()}`;
let uuid = 0;
function isBodyOverflowing() {
  return document.body.scrollHeight > (window.innerHeight || document.documentElement.clientHeight) && window.innerWidth > document.body.offsetWidth;
}
function useScrollLocker(lock) {
  const mergedLock = computed(() => !!lock && !!lock.value);
  uuid += 1;
  const id = `${UNIQUE_ID}_${uuid}`;
  watchEffect(
    (onClear) => {
      if (mergedLock.value) {
        const scrollbarSize = getScrollBarSize();
        const isOverflow = isBodyOverflowing();
        updateCSS(
          `
html body {
  overflow-y: hidden;
  ${isOverflow ? `width: calc(100% - ${scrollbarSize}px);` : ""}
}`,
          id
        );
      } else {
        removeCSS(id);
      }
      onClear(() => {
        removeCSS(id);
      });
    },
    { flush: "post" }
  );
}

export { isBodyOverflowing, useScrollLocker };
//# sourceMappingURL=useScrollLocker.mjs.map
