'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var updateAncestors = function updateAncestors(node, checkedMap) {
  if (!(node !== null && node !== void 0 && node.parent)) {
    return;
  }
  var parent = node.parent;
  var siblings = parent.items;
  var siblingsLength = siblings.length;
  var checkedFromAllSiblings = 0;
  var isParentIndeterminate = false;
  siblings.forEach(function (sib) {
    if (checkedMap.get(sib.value) === 'indeterminate') {
      isParentIndeterminate = true;
      return;
    }
    if (checkedMap.get(sib.value)) {
      checkedFromAllSiblings += 1;
    }
  });
  if (isParentIndeterminate || checkedFromAllSiblings > 0 && checkedFromAllSiblings < siblingsLength) {
    checkedMap.set(parent.value, 'indeterminate');
  } else if (checkedFromAllSiblings === 0) {
    checkedMap.set(parent.value, false);
  } else {
    checkedMap.set(parent.value, true);
  }
  updateAncestors(parent, checkedMap);
};

exports.updateAncestors = updateAncestors;
//# sourceMappingURL=updateAncestors.js.map
