"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports.PickerContentStateBI = void 0;
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var _util = require("@wix/bex-core/util");
var _bexCore = require("@wix/bex-core");
var _bi = require("@wix/bex-core/bi");
var _mobx = require("mobx");
const withoutDefaults = (0, _bexCore.withoutIrrelevant)();
class PickerContentStateBI {
  constructor(params) {
    (0, _defineProperty2.default)(this, "state", void 0);
    this.state = params.state;
  }
  init() {
    const {
      events
    } = this.state;
    const disposers = [(0, _util.addEventListener)(events, 'beforeToggleIsSelectAll', () => {
      const {
        picker,
        reportBi
      } = this.state;
      const {
        collection: {
          bulkSelect,
          query: {
            search
          }
        }
      } = picker;
      const numItemsBefore = bulkSelect.selectedCountOrTotal;
      return {
        afterToggleIsSelectAll: (0, _mobx.action)(() => {
          const {
            allSelected
          } = bulkSelect;
          reportBi(withoutDefaults(_bi.cairoItemSelectionToggled)({
            ...picker._commonDynamicBiParams(),
            url: typeof window !== 'undefined' ? window.location.href : '',
            isSelectAll: true,
            isFromSearch: !search.isEmpty,
            searchQuery: search.value,
            itemId: allSelected ? 'All' : undefined,
            clickType: allSelected ? 'Selection' : 'Deselection',
            numItemsBefore,
            numItemsAfter: bulkSelect.selectedCountOrTotal
          }));
        })
      };
    })];
    return () => {
      disposers.forEach(d => d());
    };
  }
}
exports.PickerContentStateBI = PickerContentStateBI;
//# sourceMappingURL=PickerContentStateBI.js.map