var Common;!function(i){"use strict";class t{constructor(i){this._undoLimit=100;this._singleEdit=!1;this._undoActions=0;this._doActions=0;this.reset();this._rpc=i}setLimit(i){this._undoLimit=i}getLimit(){return this._undoLimit}reset(){this._undoStack=new Array;this._doStack=new Array;this._chainingUid=null;this._chainingLevel=0}performEdit(i){var t=!1;try{t=i.performEdit()}catch(i){t=!1}if(t)if(this._singleEdit){var s=i;if(!s.getOldValue||!s.setOldValue)return!1;this._singleEditFirstEdit||(this._singleEditFirstEdit=s);this._singleEditLastEdit=s}else this._pushEdit(i);this._rpc.jsonRpcNotification("SendTestEventEditWorked",[t]);return t}startSingleEdit(){this._singleEdit=!0}endSingleEdit(){this._singleEdit=!1;if(this._singleEditFirstEdit){var i=this._singleEditFirstEdit.getOldValue();this._singleEditLastEdit.setOldValue(i);this._singleEditLastEdit.hasValueChanged()&&this._pushEdit(this._singleEditLastEdit)}this._singleEditFirstEdit=void 0;this._singleEditLastEdit=void 0}enableChaining(){this._chainingLevel++;this._chainingLevel>1||(this._chainingUid=i.RemoteHelpers.getUid())}disableChaining(){if(this._chainingLevel>0){this._chainingLevel--;if(0===this._chainingLevel){var i=this._peek(this._undoStack),t=i&&i.chainingUid===this._chainingUid;this._chainingUid=null;if(t){this._undoActions++;this._checkIfOverLimit()}}}}undo(){var i=!0;try{if(this.somethingToUndo()){var t=this._undoStack.pop();if(t.performUndo()){this._doStack.push(t);for(;this.somethingToUndo()&&t.chainingUid;){var s=this._undoStack.pop();if(s.chainingUid!==t.chainingUid){this._undoStack.push(s);break}if(!(t=s).performUndo()){this.reset();i=!1;break}this._doStack.push(t)}}else{this.reset();i=!1}this._undoActions--;this._doActions++}}catch(t){i=!1}this._rpc.jsonRpcNotification("SendTestEventUndoWorked",[i]);return i}performNextEdit(){var i=!0;try{if(this.somethingToDo()){var t=this._doStack.pop();if(t.performEdit(!0)){this._undoStack.push(t);for(;this.somethingToDo()&&t.chainingUid;){var s=this._doStack.pop();if(s.chainingUid!==t.chainingUid){this._doStack.push(s);break}if(!(t=s).performEdit(!0)){this.reset();i=!1;break}this._undoStack.push(t)}}else{this.reset();i=!1}this._undoActions++;this._doActions--}}catch(t){i=!1}this._rpc.jsonRpcNotification("SendTestEventEditWorked",[i]);return i}somethingToUndo(){return this._undoStack.length>0}somethingToDo(){return this._doStack.length>0}_pushEdit(i){i.chainingUid=this._chainingUid;this._undoStack.push(i);this._doStack=[];this._doActions=0;if(!this._chainingUid){this._undoActions++;this._checkIfOverLimit()}}_checkIfOverLimit(){for(;this._doActions+this._undoActions>this._undoLimit;){var i=this._undoStack[0];if(i.chainingUid)for(;this._undoStack.length>0&&this._undoStack[0].chainingUid===i.chainingUid;)this._undoStack.shift();else this._undoStack.shift();this._undoActions--}}_peek(i){var t=i.pop();i.push(t);return t}}t.EDIT_STACK_CALLBACK="SendTestEventEditWorked";t.UNDO_STACK_CALLBACK="SendTestEventUndoWorked";i.EditStack=t}(Common||(Common={}));
