"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports.IndeterminateMapState = void 0;
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var _mobx = require("mobx");
const statuses = {
  empty: {
    type: 'empty',
    toggle: () => statuses.partial,
    toggleCheckbox: true
  },
  partial: {
    type: 'partial',
    toggle: () => statuses.full,
    toggleCheckbox: true
  },
  full: {
    type: 'full',
    toggle: () => statuses.empty,
    toggleCheckbox: false
  }
};
class IndeterminateMapState {
  constructor() {
    (0, _defineProperty2.default)(this, "_map", _mobx.observable.map([], {
      deep: false
    }));
    (0, _mobx.makeObservable)(this, {
      toggle: _mobx.action,
      setManyPartial: _mobx.action,
      partialModeKeys: _mobx.computed,
      partialModeKeysSet: _mobx.computed
    });
  }
  toggle(key) {
    const {
      _map
    } = this;
    const currentStatus = _map.get(key);
    if (currentStatus == null) {
      return;
    }
    const nextStatus = currentStatus.toggle();
    _map.set(key, nextStatus);
    return nextStatus;
  }
  setManyPartial(keys) {
    const {
      _map
    } = this;
    for (const key of keys) {
      if (!_map.has(key)) {
        _map.set(key, statuses.partial);
      }
    }
  }
  isPartial(key) {
    var _map$get;
    const {
      _map
    } = this;
    return ((_map$get = _map.get(key)) == null ? void 0 : _map$get.type) === 'partial';
  }
  get partialModeKeys() {
    return Array.from(this._map.entries()).filter(([, value]) => value.type === 'partial').map(([key]) => key);
  }
  get partialModeKeysSet() {
    const {
      partialModeKeys
    } = this;
    return new Set(partialModeKeys);
  }
}
exports.IndeterminateMapState = IndeterminateMapState;
//# sourceMappingURL=IndeterminateMapState.js.map