/* COPYRIGHT Esri - https://js.arcgis.com/5.0/LICENSE.txt */
import{__decorate as e}from"tslib";import{makeHandle as t}from"../../core/handleUtils.js";import{destroyMaybe as r}from"../../core/maybe.js";import{property as o,subclass as i}from"../../core/accessorSupport/decorators.js";import{IDENTITY as s}from"../../core/libs/gl-matrix-2/factories/mat2df64.js";import{DrawOperation as n}from"./DrawOperation.js";import{ScreenDrawSurface as a}from"./drawSurfaces.js";import{createCircle as l,createSquare as p,createEllipse as c,createRectangle as d}from"./support/createUtils.js";import{AffineCoordinateSystem as u}from"./support/surfaceCoordinateSystems.js";import{InteractiveToolBase as m}from"../interactive/InteractiveToolBase.js";import h from"../overlay/OutlineOverlayItem.js";let g=class extends m{constructor(e){super(e),this.drawOperation=null,this._overlayItem=void 0,this.geometryType=null,this.mode=null,this.type="draw-screen"}initialize(){this.drawOperation=this._makeDrawOperation();const e=e=>this.drawOperation?.on(e,t=>{this._updateVisuals(),this.emit(e,t)})??t();this.addHandles([e("vertex-add"),e("vertex-remove"),e("vertex-update"),e("cursor-update"),e("complete")]),this.finishToolCreation()}destroy(){this.drawOperation=r(this.drawOperation),this._set("view",null)}get canRedo(){return!!this.drawOperation?.canRedo}get canUndo(){return!!this.drawOperation?.canUndo}set centeredToggled(e){this._set("centeredToggled",e),this._updateVisuals()}set enabled(e){const{drawOperation:t}=this;t&&(t.interactive=e),this._set("enabled",e)}set uniformSizeToggled(e){this._set("uniformSizeToggled",e),this._updateVisuals()}get updating(){return this.drawOperation?.updating??!1}get cursor(){return this._get("cursor")??"crosshair"}set cursor(e){this._set("cursor",e);const{drawOperation:t}=this;t&&(t.cursor=e)}completeCreateOperation(){this.drawOperation?.complete()}onInputEvent(e){this.destroyed||this.drawOperation?.onInputEvent(e)}redo(){this.drawOperation?.redo()}undo(){this.drawOperation?.undo()}reset(){}_makeDrawOperation(){const{view:e}=this;return new n({view:e,manipulators:this.manipulators,geometryType:y(this.geometryType),drawingMode:this.mode,hasZ:!1,defaultZ:0,snapToSceneEnabled:!1,drawSurface:new a,hasM:!1,snappingManager:null,snappingVisualizer:null,graphic:null,cursor:this.cursor,automaticLengthMeasurementUtils:this.automaticLengthMeasurementUtils})}get coordinates(){const{drawOperation:e}=this;if(!e?.geometryIncludingUncommittedVertices.length)return[];const{coordinateHelper:t}=e,r=e.committableVertex,o=e.committedVertices.slice();null!=r&&o.push(t.pointToArray(r));const i=o.length;switch(this.geometryType){case"point":return o.slice(0,1);case"circle":case"rectangle":{const t=new u(s,a.spatialReference),r="circle"===this.geometryType?l:p,n="circle"===this.geometryType?c:d;if(1===i&&e.isCompleted){const e=o[0],i=t.makeMapPoint(e[0]+w,e[1]);return r([e,i],t,!0)?.geometry.rings[0]??[]}if(2===i){const e="rectangle"!==this.geometryType,i=this.centeredToggled!==e,s="rectangle"!==this.geometryType;return(this.uniformSizeToggled!==s?r(o,t,i)?.geometry.rings[0]:n(o,t,i)?.geometry.rings[0])??[]}return[]}}return o}_updateVisuals(){if(!this._overlayItem){const e=new h({strokeDash:[5],strokeDashColor:[255,255,255,255]});this.view.overlay?.addItem(e),this.addHandles(t(()=>{this.view.overlay?.removeItem(e),e?.destroy(),this._overlayItem=void 0})),this._overlayItem=e}this._overlayItem.coordinates=this.coordinates}onDeactivate(){this.drawOperation?.isCompleted||this.drawOperation?.cancel()}};function y(e){switch(e){case"polygon":case"point":return e;case"circle":case"rectangle":return"segment"}}e([o({value:!1})],g.prototype,"centeredToggled",null),e([o()],g.prototype,"drawOperation",void 0),e([o({value:!0})],g.prototype,"enabled",null),e([o({value:!1})],g.prototype,"uniformSizeToggled",null),e([o({constructOnly:!0})],g.prototype,"geometryType",void 0),e([o({constructOnly:!0})],g.prototype,"mode",void 0),e([o({readOnly:!0})],g.prototype,"type",void 0),e([o({readOnly:!0})],g.prototype,"updating",null),e([o({constructOnly:!0,nonNullable:!0})],g.prototype,"view",void 0),e([o({constructOnly:!0})],g.prototype,"automaticLengthMeasurementUtils",void 0),e([o()],g.prototype,"cursor",null),g=e([i("esri.views.draw.DrawScreenTool")],g);const w=48;export{g as DrawScreenTool,y as geometryTypeToDrawOperationGeometryType};
