'use strict';

var vue = require('vue');
require('../../utils/index.cjs');
var canUseDom = require('../../utils/dom/canUseDom.cjs');
var getScrollBarSize = require('../../utils/scroll/getScrollBarSize.cjs');
var dynamicCSS = require('../../utils/dom/dynamicCSS.cjs');

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 = vue.computed(() => !!lock && !!lock.value);
  uuid += 1;
  const id = `${UNIQUE_ID}_${uuid}`;
  vue.watchEffect(
    (onClear) => {
      if (!canUseDom.canUseDom())
        return;
      if (mergedLock.value) {
        const scrollbarSize = getScrollBarSize.getScrollBarSize();
        const isOverflow = isBodyOverflowing();
        dynamicCSS.updateCSS(
          `
html body {
  overflow-y: hidden;
  ${isOverflow ? `width: calc(100% - ${scrollbarSize}px);` : ""}
}`,
          id
        );
      } else {
        dynamicCSS.removeCSS(id);
      }
      onClear(() => {
        dynamicCSS.removeCSS(id);
      });
    },
    { flush: "post" }
  );
}

exports.isBodyOverflowing = isBodyOverflowing;
exports.useScrollLocker = useScrollLocker;
//# sourceMappingURL=index.cjs.map
