"use strict";var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;exports.__esModule = true;exports.HideBodyVerticalScroll = void 0;var _taggedTemplateLiteralLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/taggedTemplateLiteralLoose"));var _inheritsLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/inheritsLoose"));var _react = _interopRequireDefault(require("react"));
var _globalObject = require("@skbkontur/global-object");

var _getScrollWidth = require("../../lib/dom/getScrollWidth");
var _Emotion = require("../../lib/theming/Emotion");var _HideBodyVerticalScroll, _templateObject;

var disposeDocumentStyle = null;var





HideBodyVerticalScroll = exports.HideBodyVerticalScroll = /*#__PURE__*/function (_React$Component) {function HideBodyVerticalScroll() {var _this;for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {args[_key] = arguments[_key];}_this = _React$Component.call.apply(_React$Component, [this].concat(args)) || this;_this.



    initialScroll = 0;_this.
    master = false;_this.


























































    restoreStyles = function () {
      if (disposeDocumentStyle) {
        disposeDocumentStyle();
        disposeDocumentStyle = null;

        if (_globalObject.globalObject.document) {
          _globalObject.globalObject.document.documentElement.scrollTop = _this.initialScroll;
        }
      }
    };return _this;}(0, _inheritsLoose2.default)(HideBodyVerticalScroll, _React$Component);var _proto = HideBodyVerticalScroll.prototype;_proto.componentDidMount = function componentDidMount() {var counter = VerticalScrollCounter.increment();if (counter === 1) {var _globalObject$documen;this.master = true;this.initialScroll = (_globalObject$documen = _globalObject.globalObject.document) != null && _globalObject$documen.documentElement ? _globalObject.globalObject.document.documentElement.scrollTop : 0;HideBodyVerticalScroll.updateScrollVisibility();_globalObject.globalObject.addEventListener == null || _globalObject.globalObject.addEventListener('resize', HideBodyVerticalScroll.updateScrollVisibility);}};_proto.componentDidUpdate = function componentDidUpdate() {if (this.master) {HideBodyVerticalScroll.updateScrollVisibility();}};_proto.componentWillUnmount = function componentWillUnmount() {var counter = VerticalScrollCounter.decrement();if (counter === 0) {this.restoreStyles();_globalObject.globalObject.removeEventListener == null || _globalObject.globalObject.removeEventListener('resize', HideBodyVerticalScroll.updateScrollVisibility);}};_proto.render = function render() {return null;};return HideBodyVerticalScroll;}(_react.default.Component);_HideBodyVerticalScroll = HideBodyVerticalScroll;HideBodyVerticalScroll.__KONTUR_REACT_UI__ = 'HideBodyVerticalScroll';HideBodyVerticalScroll.displayName = 'HideBodyVerticalScroll';HideBodyVerticalScroll.updateScrollVisibility = function () {var shouldHide = !disposeDocumentStyle;if (shouldHide) {_HideBodyVerticalScroll.hideScroll();}};HideBodyVerticalScroll.hideScroll = function () {if (!(0, _globalObject.isBrowser)(_globalObject.globalObject)) {return;}var documentElement = _globalObject.globalObject.document.documentElement;var clientHeight = documentElement.clientHeight,scrollHeight = documentElement.scrollHeight;var documentComputedStyle = _globalObject.globalObject.getComputedStyle(documentElement);var scrollbarConst = _globalObject.globalObject.getComputedStyle(documentElement).overflowY === 'scroll';var scrollWidth = clientHeight < scrollHeight || scrollbarConst ? (0, _getScrollWidth.getScrollWidth)() : 0;var documentMargin = parseFloat(documentComputedStyle.marginRight || '');var className = generateDocumentStyle(documentMargin + scrollWidth);disposeDocumentStyle = _HideBodyVerticalScroll.attachStyle(documentElement, className);};HideBodyVerticalScroll.attachStyle = function (element, className) {element.classList.add(className);return function () {element.classList.remove(className);};};var


VerticalScrollCounter = function VerticalScrollCounter() {};VerticalScrollCounter.
increment = function () {
  var globalWithRetailUIVerticalScrollCounter = _globalObject.globalObject;
  var counter = globalWithRetailUIVerticalScrollCounter.RetailUIVerticalScrollCounter || 0;
  return globalWithRetailUIVerticalScrollCounter.RetailUIVerticalScrollCounter = counter + 1;
};VerticalScrollCounter.

decrement = function () {
  var globalWithRetailUIVerticalScrollCounter = _globalObject.globalObject;
  var counter = globalWithRetailUIVerticalScrollCounter.RetailUIVerticalScrollCounter || 0;
  return globalWithRetailUIVerticalScrollCounter.RetailUIVerticalScrollCounter = counter - 1;
};VerticalScrollCounter.

get = function () {
  var globalWithRetailUIVerticalScrollCounter = _globalObject.globalObject;
  return globalWithRetailUIVerticalScrollCounter.RetailUIVerticalScrollCounter || 0;
};


function generateDocumentStyle(documentMargin) {
  return (0, _Emotion.css)(_templateObject || (_templateObject = (0, _taggedTemplateLiteralLoose2.default)(["\n    overflow: hidden !important;\n    margin-right: ", "px !important;\n    height: 100%;\n  "])),

  documentMargin);


}