/* COPYRIGHT Esri - https://js.arcgis.com/5.1.0/LICENSE.txt */
import{__decorate as e}from"tslib";import{isSome as t}from"../../../core/arrayUtils.js";import o from"../../../core/Collection.js";import{EventedAccessor as r}from"../../../core/Evented.js";import{property as s,subclass as n}from"../../../core/accessorSupport/decorators.js";import{getLegacyTool as i}from"./sketchUtils.js";let p=class extends r{constructor(e){super(e),this.cancelled=!1,this.history={undo:new o,redo:new o},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 i(e.pluginStack.toArray().map(e=>e?.configuration).filter(t))??null}return null}addToHistory(e){this.history.redo.removeAll(),this.history.undo.push(e)}resetHistory(){this.history.redo.removeAll(),this.history.undo.removeAll()}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([s()],p.prototype,"activeComponent",void 0),e([s()],p.prototype,"cancelled",void 0),e([s()],p.prototype,"history",void 0),e([s()],p.prototype,"tool",null),e([s()],p.prototype,"type",void 0),e([s()],p.prototype,"canUndo",null),e([s()],p.prototype,"canRedo",null),e([s()],p.prototype,"onEnd",void 0),e([s()],p.prototype,"undo",null),e([s()],p.prototype,"redo",null),e([s()],p.prototype,"toggleTool",void 0),e([s()],p.prototype,"addToSelection",void 0),e([s()],p.prototype,"removeFromSelection",void 0),p=e([n("esri.widgets.Sketch.support.OperationHandle")],p);let a=class extends p{};e([s()],a.prototype,"activeComponent",void 0),a=e([n("esri.widgets.Sketch.support.OperationHandle.CreateOperationHandle")],a);let l=class extends p{};e([s()],l.prototype,"activeComponent",void 0),l=e([n("esri.widgets.Sketch.support.OperationHandle.UpdateOperationHandle")],l);let c=class extends p{};e([s()],c.prototype,"activeComponent",void 0),c=e([n("esri.widgets.Sketch.support.OperationHandle.DrawToolOperationHandle")],c);export{a as CreateOperationHandle,c as DrawToolOperationHandle,p as OperationHandle,l as UpdateOperationHandle};
