"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports.CollectionToolbarFiltersState = void 0;
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var _bexCore = require("@wix/bex-core");
var _bi = require("@wix/bex-core/bi");
var _mobx = require("mobx");
var _react = require("react");
class CollectionToolbarFiltersState {
  constructor(params) {
    (0, _defineProperty2.default)(this, "toolbar", void 0);
    (0, _defineProperty2.default)(this, "panelTitle", new _bexCore.ValueBox(undefined));
    (0, _defineProperty2.default)(this, "totalInlineFilters", new _bexCore.ValueBox(null));
    (0, _defineProperty2.default)(this, "filterElements", new _bexCore.ValueBox([]));
    (0, _defineProperty2.default)(this, "moreFiltersButtonRef", /*#__PURE__*/(0, _react.createRef)());
    (0, _defineProperty2.default)(this, "onClearButtonClicked", void 0);
    (0, _defineProperty2.default)(this, "onFiltersButtonClick", (0, _mobx.action)(() => {
      const actionStartTime = performance.now();
      const {
        reportBi
      } = this.toolbar;
      const isOpened = this.toolbar.panels.toggleSidePanel('filters');
      // to be called after the panel is opened/closed and call stack is cleared
      window.setTimeout(() => {
        reportBi((0, _bexCore.withoutDefaults)(_bi.cairoFiltersPanelUsed)({
          ...this.toolbar._commonDynamicBiParams(),
          isOpened,
          origin: 'Filter Button',
          feature: 'Filter',
          timeFromAction: Math.round(performance.now() - actionStartTime)
        }));
      });
    }));
    this.toolbar = params.toolbar;
    (0, _mobx.makeObservable)(this, {
      panelFilterElements: _mobx.computed,
      panelFilters: _mobx.computed
    });
  }
  get panelFilterElements() {
    const {
      totalInlineFilters: {
        value: totalInlineFilters
      },
      filterElements: {
        value: filterElements
      }
    } = this;
    return totalInlineFilters != null ? filterElements.slice(totalInlineFilters) : [];
  }
  get panelFilters() {
    return this.panelFilterElements.map(element => element.props.filter);
  }
}
exports.CollectionToolbarFiltersState = CollectionToolbarFiltersState;
//# sourceMappingURL=CollectionToolbarFiltersState.js.map