"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports.HorizontalOverflowState = void 0;
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var _mobx = require("mobx");
var _bexCore = require("@wix/bex-core");
class HorizontalOverflowState {
  constructor(params) {
    (0, _defineProperty2.default)(this, "_syncThrottled", void 0);
    (0, _defineProperty2.default)(this, "container", void 0);
    (0, _defineProperty2.default)(this, "_state", void 0);
    (0, _defineProperty2.default)(this, "_element", void 0);
    (0, _defineProperty2.default)(this, "_scrollWidth", 0);
    (0, _defineProperty2.default)(this, "_clientWidth", 0);
    const {
      state
    } = params;
    this.container = state.container;
    this._state = state;
    (0, _mobx.makeObservable)(this, {
      _sync: _mobx.action.bound,
      _scrollWidth: _mobx.observable.ref,
      _clientWidth: _mobx.observable.ref,
      _isOverflowing: _mobx.computed
    });
    this._syncThrottled = this.container.lodash.throttle(() => {
      window.requestAnimationFrame(this._sync);
    }, 200);
  }
  get _isOverflowing() {
    return this._scrollWidth > this._clientWidth;
  }
  _sync() {
    const {
      _element
    } = this;
    if (!_element) {
      return;
    }
    this._clientWidth = _element.clientWidth;
    this._scrollWidth = _element.scrollWidth;
  }
  initLayout() {
    const {
      _element,
      _state
    } = this;
    if (_state.responsiveDisabled) {
      return;
    }
    if (!_element) {
      return;
    }
    this._sync();
  }
  init() {
    const {
      _element,
      _state
    } = this;
    if (_state.responsiveDisabled) {
      return;
    }
    if (!_element) {
      return;
    }
    const disposers = [(0, _bexCore.addResizeObserver)(_element, this._syncThrottled)];
    return () => {
      disposers.forEach(d => d == null ? void 0 : d());
    };
  }
}
exports.HorizontalOverflowState = HorizontalOverflowState;
//# sourceMappingURL=HorizontalOverflowState.js.map