/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.24/esri/copyright.txt for details.
*/
define(["exports","../../../../chunks/_rollupPluginBabelHelpers","../../../../chunks/tslib.es6","../../../../core/handleUtils","../../../../core/maybe","../../../../core/reactiveUtils","../../../../core/accessorSupport/decorators/property","../../../../core/arrayUtils","../../../../core/has","../../../../core/accessorSupport/ensureType","../../../../core/accessorSupport/decorators/subclass","../../../../geometry/support/vectorStacks","./LengthDimensionSubTool","../../webgl-engine/lib/Intersector","../../webgl-engine/lib/IntersectorInterfaces","../../../interactive/AnalysisToolBase","../../../support/screenUtils"],(function(e,o,i,t,n,s,r,a,l,c,u,p,d,h,m,_,y){"use strict";var g;!function(e){e.Ready="ready",e.Creating="creating",e.Created="created"}(g||(g={})),e.DimensioningTool=function(e){function i(o){var i;return(i=e.call(this,o)||this).preferManipulatorCursor=!0,i.analysisViewData=null,i}o._inheritsLoose(i,e);var r=i.prototype;return r.initialize=function(){this._intersector=h.newIntersector(this.view.state.viewingMode),this._intersector.options.store=m.StoreResults.MIN,this._lengthDimensionSubTool=new d.LengthDimensionSubTool({view:this.view}),this.own(t.destroyHandle(this._lengthDimensionSubTool));for(const e of this.analysis.dimensions.items)this._addDimension(e);this.own(this.analysis.dimensions.on("change",(e=>{for(const o of e.added)this._addDimension(o);for(const o of e.removed)this._removeDimension(o)}))),this.own(s.watch((()=>this.state),(e=>{e===g.Created&&this.finishToolCreation()}),s.syncAndInitial))},r.getManipulatorsForDimension=function(e){return this._lengthDimensionSubTool.getManipulatorsForDimension(e)},r.onInputEvent=function(e){switch(e.type){case"immediate-click":this._clickHandler(e);break;case"immediate-double-click":this._doubleClickHandler(e);break;case"pointer-move":this._pointerMoveHandler(e)}},r.onActivate=function(){this._activeSubTool=this._lengthDimensionSubTool},r.onDeactivate=function(){n.isSome(this._activeSubTool)&&(this._activeSubTool.onDeactivate(),n.isSome(this._activeSubTool.stagedDimension)&&(this.analysis.dimensions.remove(this._activeSubTool.stagedDimension),this._activeSubTool.stagedDimension=null),this._activeSubTool=null)},r._clickHandler=function(e){if(n.isNone(this._activeSubTool))return;const o=this._intersectScreen(e);if(!n.isNone(o)){if(n.isNone(this._activeSubTool.stagedDimension)){const i=this._activeSubTool.onUnstagedClick({mapPoint:o,pointerType:e.pointerType});this.analysis.dimensions.add(i)}else this._activeSubTool.onStagedClick({mapPoint:o,pointerType:e.pointerType});e.stopPropagation()}},r._doubleClickHandler=function(e){this.view.activeTool=null,e.stopPropagation()},r._pointerMoveHandler=function(e){if(n.isNone(this._activeSubTool))return;if(this.hasFocusedManipulators)return;const o=this._intersectScreen(e);n.isNone(o)||this._activeSubTool.onPointerMove({mapPoint:o,pointerType:e.pointerType})},r._intersectScreen=function(e){const o=y.createScreenPointArrayFromEvent(e);this.view.sceneIntersectionHelper.intersectToolIntersectorScreen(o,this._intersector);const i=this._intersector.results.min,t=p.sv3d.get();return i.getIntersectionPoint(t)?this.view.renderCoordsHelper.fromRenderCoords(t,this.view.spatialReference):null},r._addDimension=function(e){this._lengthDimensionSubTool.addDimension(e,this.manipulators)},r._removeDimension=function(e){this._lengthDimensionSubTool.removeDimension(e,this.manipulators)},o._createClass(i,[{key:"state",get:function(){return this.analysis.dimensions.some((e=>"length"===e.type))?n.isSome(this._activeSubTool)?g.Creating:g.Created:g.Ready}},{key:"updating",get:function(){return this._lengthDimensionSubTool.updating}},{key:"cursor",get:function(){return this.active?"crosshair":null}}]),i}(_.AnalysisToolBase),i.__decorate([r.property({constructOnly:!0})],e.DimensioningTool.prototype,"view",void 0),i.__decorate([r.property({constructOnly:!0})],e.DimensioningTool.prototype,"analysis",void 0),i.__decorate([r.property({readOnly:!0})],e.DimensioningTool.prototype,"state",null),i.__decorate([r.property({readOnly:!0})],e.DimensioningTool.prototype,"updating",null),i.__decorate([r.property({readOnly:!0})],e.DimensioningTool.prototype,"cursor",null),i.__decorate([r.property({readOnly:!0})],e.DimensioningTool.prototype,"preferManipulatorCursor",void 0),i.__decorate([r.property({constructOnly:!0})],e.DimensioningTool.prototype,"analysisViewData",void 0),i.__decorate([r.property()],e.DimensioningTool.prototype,"_activeSubTool",void 0),i.__decorate([r.property()],e.DimensioningTool.prototype,"_lengthDimensionSubTool",void 0),e.DimensioningTool=i.__decorate([u.subclass("esri.views.3d.analysis.Dimensioning.DimensioningTool")],e.DimensioningTool),Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
