/* 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"../../../../core/has.js";import{watch as i,syncAndInitial as n,when as a}from"../../../../core/reactiveUtils.js";import{property as s,subclass as o}from"../../../../core/accessorSupport/decorators.js";import{absoluteHeightElevationInfo as r}from"../../../../support/elevationInfoUtils.js";import{LineOfSightDrawToolRenderer as l}from"./LineOfSightDrawToolRenderer.js";import{createLineOfSightRootPluginConfiguration as p}from"./LineOfSightRootPlugin.js";import{Manipulator3D as h}from"../../interactive/Manipulator3D.js";import{DrawTool as c}from"../../../draw/DrawTool.js";import{mouseButtons as u}from"../../../input/mouseButtons.js";import d from"../../../interactive/sketch/SketchOptions.js";import{acquire as v}from"../../../interactive/snapping/SnappingManagerPool.js";const g=Symbol("hiddenManipulatorHandle"),m=Symbol("snappingManagerHandle");let f=class extends c{constructor(e){super({...e,enableVertexVisuals:!1,sketchOptions:new d({tooltips:{enabled:!0}}),snappingManager:null,elevationInfo:null,hasZ:!0}),this.removeIncompleteOnCancel=!1,this.placementElevationInfo=null,this._snappingManagerResult=null,this.renderer=new l({view:e.view})}initialize(){this.addHandles([i(()=>[this.surfaceManager,this._snapToSceneEnabled],([e,t])=>{e&&(e.snapToSceneEnabled=t)},n),i(()=>this.manipulators.length,()=>this._hideManipulatorOnAppearance(),n),a(()=>!this.active,()=>{this.analysisViewData.cursorTarget=null},n),i(()=>this.analysisViewData.visible,e=>{this.visible=e},n),i(()=>this.parent.editable,e=>{this.editable=e},n),i(()=>this._sourceElevationInfo,e=>{this.elevationInfo=e,this.renderer.elevationInfo=e,this.renderer.refresh()},n),i(()=>this.analysis.valid,()=>this._syncCreatedState(),n)])}destroy(){this.removeHandles(g)}get state(){return this.active?"creating":null!=this.analysis.observer?.position?"created":"ready"}get _snapToSceneEnabled(){const e=this._sourceElevationInfo?.mode;return"relative-to-ground"!==e&&"on-the-ground"!==e&&null}get _defaultElevationInfo(){return this.placementElevationInfo}get _sourceElevationInfo(){return this.placementElevationInfo??r}deactivate(){super.deactivate(),this._releaseSnappingManager(),this.created||(this.analysis.clear(),this.analysisViewData.cursorTarget=null)}resetCreated(){this._set("created",!1),this._syncCreatedState()}_syncCreatedState(){this.analysis.valid&&this.finishToolCreation()}place(){this.begin([p({analysis:this.analysis,analysisViewData:this.analysisViewData,authoringStore:this.authoringStore,defaultElevationInfo:this._defaultElevationInfo,sourceElevationInfo:this._sourceElevationInfo,view:this.view})])}continue(){this._ensureSnappingManager(),this.view.activeTool!==this&&(this.view.activeTool=this),0===this.pluginStack.length&&this.place()}stop(){if(!this.active)return;const e=this.mostUpstreamPlugin;e&&this.lifecycleManager.cancel(e),this.view.activeTool===this&&(this.view.activeTool=null)}get testInfo(){}onInputEvent(e){if("immediate-click"===e.type&&"mouse"===e.pointerType){if(e.button===u.Right)return;if(e.native.detail>1)return}super.onInputEvent(e)}_hideManipulatorOnAppearance(){this.removeHandles(g),this.addHandles(this.manipulators.toArray().map(e=>e instanceof h?e.disableDisplay():null).filter(t),g)}_ensureSnappingManager(){if(this._snappingManagerResult)return;const e=v(this.view);this._snappingManagerResult=e,this.snappingManager=e.snappingManager,this.addHandles(e,m)}_releaseSnappingManager(){this._snappingManagerResult&&(this.snappingManager?.doneSnapping(),this.snappingManager=null,this.removeHandles(m),this._snappingManagerResult=null)}};e([s({constructOnly:!0})],f.prototype,"view",void 0),e([s({constructOnly:!0})],f.prototype,"analysis",void 0),e([s({constructOnly:!0})],f.prototype,"analysisViewData",void 0),e([s({constructOnly:!0})],f.prototype,"authoringStore",void 0),e([s({constructOnly:!0})],f.prototype,"parent",void 0),e([s()],f.prototype,"renderer",void 0),e([s()],f.prototype,"removeIncompleteOnCancel",void 0),e([s()],f.prototype,"placementElevationInfo",void 0),e([s()],f.prototype,"_snappingManagerResult",void 0),e([s()],f.prototype,"state",null),f=e([o("esri.views.3d.analysis.LineOfSight.LineOfSightPlacementTool")],f);export{f as LineOfSightPlacementTool};
