/* COPYRIGHT Esri - https://js.arcgis.com/5.1.0/LICENSE.txt */
import{__decorate as e}from"tslib";import t from"../../../../core/Accessor.js";import"../../../../core/has.js";import{destroyMaybe as i}from"../../../../core/maybe.js";import{watch as s,syncAndInitial as o}from"../../../../core/reactiveUtils.js";import{property as a,subclass as l}from"../../../../core/accessorSupport/decorators.js";import{detachToolFromView as n}from"./toolLifecycleUtils.js";import{ViewshedEditTool as d}from"./ViewshedEditTool.js";import{ViewshedPlacementController as r}from"./ViewshedPlacementController.js";let c=class extends t{constructor(e){super(e),this._editTool=null}initialize(){const{view:e}=this;this._placementController=new r({analysis:this.analysis,analysisViewData:this.analysisViewData,view:e,callbacks:{cancelTool:()=>{null!=e.activeTool&&(e.activeTool=null)},findViewshedComputedData:e=>this._findViewshedComputedData(e),isToolDestroyed:()=>this.destroyed,setSelectedViewshed:e=>{this.analysisViewData.selectedViewshed=e}}}),this.addHandles([s(()=>({creationState:this._placementController.creationState,interactive:this.analysisViewData.interactive,selectedViewshed:this.analysisViewData.selectedViewshed,selectedViewshedComputedData:this._selectedViewshedComputedData}),({creationState:t,interactive:i,selectedViewshed:s,selectedViewshedComputedData:o})=>{if(!i)return this._placementController.cancelPlaceOperation(),this.analysisViewData.selectedViewshed=null,void this._destroyEditTool();null==s||null!=o?null==t?this._editTool||(this._editTool=new d({analysis:this.analysis,analysisViewData:this.analysisViewData,view:e}),e.tools.add(this._editTool)):this._destroyEditTool():this.analysisViewData.selectedViewshed=null},o),s(()=>e.activeTool,e=>{null!=e&&e!==this._editTool&&null==this._placementController.creationState&&(this.analysisViewData.selectedViewshed=null)})])}destroy(){this._destroyEditTool(),i(this._placementController)}get selectedViewshedComputedData(){return this._selectedViewshedComputedData}get stagedViewshed(){return this._placementController.stagedViewshed}get active(){return this._placementController.active||(this._editTool?.active??!1)}get updating(){return this._placementController.updating||!!this._editTool?.updating}get creating(){return null!=this._placementController.creationState}async place(e,t){if(this.analysisViewData.interactive=!0,this._destroyEditTool(),await this._placementController.startPlaceOperation(e,t),"single"===e)return{}}get _selectedViewshedComputedData(){const e=this.analysisViewData.selectedViewshed;return null==e?null:this._findViewshedComputedData(e)}_findViewshedComputedData(e){return this.analysisViewData.viewshedComputedDataHandles?.find(t=>t.viewshedComputedData.viewshed===e)?.viewshedComputedData}_destroyEditTool(){const e=this._editTool;this._editTool=null,null!=e&&(n(this.view,e),i(e))}get test(){}};e([a({constructOnly:!0})],c.prototype,"view",void 0),e([a({constructOnly:!0})],c.prototype,"analysis",void 0),e([a({constructOnly:!0})],c.prototype,"analysisViewData",void 0),e([a()],c.prototype,"_placementController",void 0),e([a()],c.prototype,"_editTool",void 0),e([a()],c.prototype,"selectedViewshedComputedData",null),e([a()],c.prototype,"stagedViewshed",null),e([a()],c.prototype,"active",null),e([a()],c.prototype,"updating",null),e([a()],c.prototype,"creating",null),e([a()],c.prototype,"_selectedViewshedComputedData",null),c=e([l("esri.views.3d.analysis.Viewshed.ViewshedTool2")],c);const h=c;export{h as default};
