/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.24/esri/copyright.txt for details.
*/
define(["../../chunks/_rollupPluginBabelHelpers","../../chunks/tslib.es6","../../core/Error","../../core/Evented","../../core/HandleOwner","../../core/accessorSupport/decorators/property","../../core/arrayUtils","../../core/has","../../core/accessorSupport/ensureType","../../core/accessorSupport/decorators/subclass"],(function(t,e,n,r,s,o,i,a,p,c){"use strict";let h=function(e){function r(t){var n;return(n=e.call(this,t)||this)._indexHistory=[],n._lastStepIndex=-1,n._stepIndex=-1,n._handleKeys={afterCommit:"after-commit",beforeCommit:"before-commit"},n.data=void 0,n.started=!1,n.steps=[],n.type=null,n}t._inheritsLoose(r,e);var s=r.prototype;return s.cancel=function(){var e=t._asyncToGenerator((function*(t={force:!0}){return!1!==t.force?this._cancel():new Promise(((t,e)=>{this.emit("cancel-request",{controller:{allow:()=>{this._cancel().then(t)},deny:()=>e(new n("workflow:cancel-denied","Request to cancel workflow was denied."))}})}))}));function r(){return e.apply(this,arguments)}return r}(),s.commit=function(){var e=t._asyncToGenerator((function*(){this.handles.remove(this._handleKeys.beforeCommit),yield this.onCommit(this.data),this.handles.remove(this._handleKeys.afterCommit),this.emit("commit"),this.started&&(yield this.reset())}));function n(){return e.apply(this,arguments)}return n}(),s.go=function(){var e=t._asyncToGenerator((function*(t){const{steps:e}=this,n=e.findIndex((e=>e.id===t));this._indexHistory.push(this._stepIndex),yield this._go(n)}));function n(t){return e.apply(this,arguments)}return n}(),s.next=function(){var e=t._asyncToGenerator((function*(){this._indexHistory.push(this._stepIndex),yield this._go(this._stepIndex+1)}));function n(){return e.apply(this,arguments)}return n}(),s.previous=function(){var e=t._asyncToGenerator((function*(t={cancelCurrentStep:!1}){yield this._go(this._indexHistory.pop(),t.cancelCurrentStep)}));function n(){return e.apply(this,arguments)}return n}(),s.reset=function(){var e=t._asyncToGenerator((function*(){yield this._cancel(!1),yield this.start()}));function n(){return e.apply(this,arguments)}return n}(),s.start=function(){var e=t._asyncToGenerator((function*(){this._set("started",!0);const t=-1===this._stepIndex?0:this._stepIndex;yield this._go(t)}));function n(){return e.apply(this,arguments)}return n}(),s._cancel=function(){var e=t._asyncToGenerator((function*(t=!0){this.started&&(this._set("started",!1),yield this.steps[this._stepIndex].tearDown({cancelled:!0}),this.data&&this.data.viewModel.sketchViewModel.layer.removeAll()),this.handles.remove([this._handleKeys.afterCommit,this._handleKeys.beforeCommit]),this._resetIndexing(t),t&&this.emit("cancel")}));function n(){return e.apply(this,arguments)}return n}(),s._go=function(){var e=t._asyncToGenerator((function*(t=-1,e=!1){if(!(t<=-1||t>=this.steps.length)){if(!this.started)return this._stepIndex=t,void this._notifyStepProps();this._lastStepIndex>-1&&(yield this.steps[this._lastStepIndex].tearDown({cancelled:e})),yield this.steps[t].setUp(),this._lastStepIndex=t,this._stepIndex=t,this._notifyStepProps()}}));function n(){return e.apply(this,arguments)}return n}(),s._resetIndexing=function(t=!0){this._stepIndex=-1,this._lastStepIndex=-1,this._indexHistory.length=0,t&&this._notifyStepProps()},s._notifyStepProps=function(){this.notifyChange("stepId"),this.notifyChange("hasPreviousStep"),this.notifyChange("hasNextStep")},t._createClass(r,[{key:"hasNextStep",get:function(){const{steps:t}=this;return!!(t&&this._stepIndex<t.filter((t=>!t.parent)).length-1)}},{key:"hasPreviousStep",get:function(){return this._stepIndex>0}},{key:"stepId",get:function(){const{steps:t}=this,e=t&&t[this._stepIndex];return e&&e.id}}]),r}(s.HandleOwnerMixin(r.EventedAccessor));e.__decorate([o.property()],h.prototype,"data",void 0),e.__decorate([o.property()],h.prototype,"hasNextStep",null),e.__decorate([o.property()],h.prototype,"hasPreviousStep",null),e.__decorate([o.property()],h.prototype,"onCommit",void 0),e.__decorate([o.property()],h.prototype,"started",void 0),e.__decorate([o.property({readOnly:!0})],h.prototype,"stepId",null),e.__decorate([o.property()],h.prototype,"steps",void 0),e.__decorate([o.property({readOnly:!0})],h.prototype,"type",void 0),e.__decorate([o.property()],h.prototype,"commit",null),h=e.__decorate([c.subclass("esri.widgets.Editor.Workflow")],h);return h}));
