import { addUniqueItem as n, removeItem as u } from "../../utils/array.es.js";
var f = function() {
  function s() {
    this.members = [];
  }
  return s.prototype.add = function(e) {
    n(this.members, e), e.scheduleRender();
  }, s.prototype.remove = function(e) {
    if (u(this.members, e), e === this.prevLead && (this.prevLead = void 0), e === this.lead) {
      var r = this.members[this.members.length - 1];
      r && this.promote(r);
    }
  }, s.prototype.relegate = function(e) {
    var r = this.members.findIndex(function(a) {
      return e === a;
    });
    if (r === 0)
      return !1;
    for (var i, t = r; t >= 0; t--) {
      var o = this.members[t];
      if (o.isPresent !== !1) {
        i = o;
        break;
      }
    }
    return i ? (this.promote(i), !0) : !1;
  }, s.prototype.promote = function(e, r) {
    var i, t = this.lead;
    if (e !== t && (this.prevLead = t, this.lead = e, e.show(), t)) {
      t.instance && t.scheduleRender(), e.scheduleRender(), e.resumeFrom = t, r && (e.resumeFrom.preserveOpacity = !0), t.snapshot && (e.snapshot = t.snapshot, e.snapshot.latestValues = t.animationValues || t.latestValues, e.snapshot.isShared = !0), !((i = e.root) === null || i === void 0) && i.isUpdating && (e.isLayoutDirty = !0);
      var o = e.options.crossfade;
      o === !1 && t.hide();
    }
  }, s.prototype.exitAnimationComplete = function() {
    this.members.forEach(function(e) {
      var r, i, t, o, a;
      (i = (r = e.options).onExitComplete) === null || i === void 0 || i.call(r), (a = (t = e.resumingFrom) === null || t === void 0 ? void 0 : (o = t.options).onExitComplete) === null || a === void 0 || a.call(o);
    });
  }, s.prototype.scheduleRender = function() {
    this.members.forEach(function(e) {
      e.instance && e.scheduleRender(!1);
    });
  }, s.prototype.removeLeadSnapshot = function() {
    this.lead && this.lead.snapshot && (this.lead.snapshot = void 0);
  }, s;
}();
export {
  f as NodeStack
};
//# sourceMappingURL=stack.es.js.map
