"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports.GridSectionsState = void 0;
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var _mobx = require("mobx");
class GridSectionsState {
  constructor(params) {
    (0, _defineProperty2.default)(this, "renderSection", void 0);
    (0, _defineProperty2.default)(this, "toolbar", void 0);
    (0, _defineProperty2.default)(this, "collection", void 0);
    (0, _defineProperty2.default)(this, "parentState", void 0);
    this.collection = params.collection;
    this.toolbar = params.toolbar;
    this.renderSection = params.renderSection;
    this.parentState = params.parentState;
    (0, _mobx.makeObservable)(this, {
      sections: _mobx.computed,
      renderSection: _mobx.observable.ref
    });
  }
  get sections() {
    const {
      collection,
      renderSection
    } = this;
    if (!renderSection) {
      return [];
    }
    return Object.values(collection.result.items.reduce((acc, item, index) => {
      const section = renderSection(item);
      if (!acc[section.id]) {
        acc[section.id] = {
          section,
          range: {
            start: index,
            length: 0
          }
        };
      }
      acc[section.id].range.length++;
      return acc;
    }, {}));
  }
}
exports.GridSectionsState = GridSectionsState;
//# sourceMappingURL=GridSectionsState.js.map