/* COPYRIGHT Esri - https://js.arcgis.com/5.0.18/LICENSE.txt */
import{__decorate as e}from"tslib";import{isSome as t}from"../../../core/arrayUtils.js";import{EventedAccessor as o}from"../../../core/Evented.js";import{property as r,subclass as s}from"../../../core/accessorSupport/decorators.js";import{getLegacyTool as n}from"./sketchUtils.js";let i=class extends o{constructor(e){super(e),this.cancelled=!1,this.history={undo:[],redo:[]},this.type=null}get tool(){const{activeComponent:e}=this;if(!e)return null;switch(e.type){case"graphic-mover":case"move-3d":return"move";case"box":case"transform-3d":return"transform";case"reshape":case"reshape-3d":return"reshape";case"draw-2d":return"text"===e.graphicSymbol?.type?"text":e.geometryType;case"draw-3d":return e.geometryType;case"draw-2.0":return n(e.pluginStack.toArray().map(e=>e?.configuration).filter(t))??null}return null}addToHistory(e){this.history.redo=[],this.history.undo.push(e)}resetHistory(){this.history.redo=[],this.history.undo=[]}canUndo(){return this.history.undo.length>0}canRedo(){return this.history.redo.length>0}complete(){const{activeComponent:e}=this;e&&"reset"in e?e.reset():e&&"complete"in e&&e.mostUpstreamPlugin&&e.complete(e.mostUpstreamPlugin),this.onEnd(),this.emit("complete")}cancel(){this.cancelled=!0;const{activeComponent:e}=this;e&&"reset"in e&&e.reset(),this.onEnd(),this.emit("complete")}refreshComponent(){const e=this.activeComponent;e&&("box"!==e.type&&"reshape"!==e.type&&"graphic-mover"!==e.type||e.refresh())}set undo(e){this._set("undo",()=>{this.canUndo()&&e()})}set redo(e){this._set("redo",()=>{this.canRedo()&&e()})}};e([r()],i.prototype,"activeComponent",void 0),e([r()],i.prototype,"cancelled",void 0),e([r()],i.prototype,"history",void 0),e([r()],i.prototype,"tool",null),e([r()],i.prototype,"type",void 0),e([r()],i.prototype,"canUndo",null),e([r()],i.prototype,"canRedo",null),e([r()],i.prototype,"onEnd",void 0),e([r()],i.prototype,"undo",null),e([r()],i.prototype,"redo",null),e([r()],i.prototype,"toggleTool",void 0),e([r()],i.prototype,"addToSelection",void 0),e([r()],i.prototype,"removeFromSelection",void 0),i=e([s("esri.widgets.Sketch.support.OperationHandle")],i);let p=class extends i{};e([r()],p.prototype,"activeComponent",void 0),p=e([s("esri.widgets.Sketch.support.OperationHandle.CreateOperationHandle")],p);let a=class extends i{};e([r()],a.prototype,"activeComponent",void 0),a=e([s("esri.widgets.Sketch.support.OperationHandle.UpdateOperationHandle")],a);let d=class extends i{};e([r()],d.prototype,"activeComponent",void 0),d=e([s("esri.widgets.Sketch.support.OperationHandle.DrawToolOperationHandle")],d);export{p as CreateOperationHandle,d as DrawToolOperationHandle,i as OperationHandle,a as UpdateOperationHandle};
