"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports.ToolbarLeftGroupState = void 0;
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var _bexCore = require("@wix/bex-core");
class ToolbarLeftGroupState {
  constructor(params) {
    (0, _defineProperty2.default)(this, "_responsive", void 0);
    (0, _defineProperty2.default)(this, "_getTabsState", void 0);
    (0, _defineProperty2.default)(this, "_element", null);
    (0, _defineProperty2.default)(this, "_tabsWidthTimeout", null);
    (0, _defineProperty2.default)(this, "mode", void 0);
    (0, _defineProperty2.default)(this, "minWidth", void 0);
    (0, _defineProperty2.default)(this, "_handleResize", () => {
      const element = this._element;
      if (!element) {
        return;
      }
      if (this.mode === 'tabs') {
        if (this._tabsWidthTimeout) {
          clearTimeout(this._tabsWidthTimeout);
        }
        this._tabsWidthTimeout = setTimeout(() => {
          var _this$_getTabsState;
          this._tabsWidthTimeout = null;
          if (!this._element) return;
          const tabsState = (_this$_getTabsState = this._getTabsState) == null ? void 0 : _this$_getTabsState.call(this);
          tabsState == null || tabsState.responsive.setAvailableWidth(this._element.clientWidth);
        }, 300);
      }
      this._responsive._scheduleRecompute();
    });
    this._responsive = params.responsive;
    this.mode = params.mode;
    this.minWidth = params.minWidth;
    this._getTabsState = params.getTabsState;
  }
  getExcessWidth() {
    if (!this._element) {
      return 0;
    }
    return Math.max(0, this._element.clientWidth - this.minWidth);
  }
  init(element) {
    this._element = null;
    if (!element) {
      return () => {};
    }
    this._element = element;
    const disposer = (0, _bexCore.addResizeObserver)(element, this._handleResize);
    return () => {
      disposer == null || disposer();
      if (this._tabsWidthTimeout) {
        clearTimeout(this._tabsWidthTimeout);
        this._tabsWidthTimeout = null;
      }
      this._element = null;
    };
  }
}
exports.ToolbarLeftGroupState = ToolbarLeftGroupState;
//# sourceMappingURL=ToolbarLeftGroupState.js.map