"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = measureScrollbar;

var _shared = require("choerodon-ui/shared");

function measureScrollbar() {
  var direction = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'vertical';

  if (typeof window === 'undefined') {
    return 0;
  }

  if (direction === 'vertical') {
    var SCROLL_BAR_WIDTH_VERTICAL = _shared.global.SCROLL_BAR_WIDTH_VERTICAL;

    if (SCROLL_BAR_WIDTH_VERTICAL !== undefined) {
      return SCROLL_BAR_WIDTH_VERTICAL;
    }
  } else {
    var SCROLL_BAR_WIDTH_HORIZONTAL = _shared.global.SCROLL_BAR_WIDTH_HORIZONTAL;

    if (SCROLL_BAR_WIDTH_HORIZONTAL !== undefined) {
      return SCROLL_BAR_WIDTH_HORIZONTAL;
    }
  }

  var scrollDiv = document.createElement('div');
  scrollDiv.style.cssText = 'position: absolute;width: 50px;height: 50px;top: -9999px; overflow: scroll';
  document.body.appendChild(scrollDiv);
  var size = 0;

  if (direction === 'vertical') {
    size = scrollDiv.offsetWidth - scrollDiv.clientWidth;
    _shared.global.SCROLL_BAR_WIDTH_VERTICAL = size;
  } else {
    size = scrollDiv.offsetHeight - scrollDiv.clientHeight;
    _shared.global.SCROLL_BAR_WIDTH_HORIZONTAL = size;
  }

  document.body.removeChild(scrollDiv);
  return size;
}
//# sourceMappingURL=measureScrollbar.js.map
