'use strict';

var vue = require('vue');
var getScrollBarSize = require('../_util/getScrollBarSize.js');
var dynamicCSS = require('../vc-util/Dom/dynamicCSS.js');

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 (mergedLock.value) {
        const scrollbarSize = getScrollBarSize.default();
        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=useScrollLocker.js.map
