/* COPYRIGHT Esri - https://js.arcgis.com/5.1.0/LICENSE.txt */
import{__decorate as e}from"tslib";import r from"../../core/Accessor.js";import{equals as s}from"../../core/arrayUtils.js";import o from"../../core/Collection.js";import t from"../../core/Error.js";import i from"../../core/Logger.js";import{mapCollection as n}from"../../core/mapCollectionUtils.js";import{isPromiseLike as a}from"../../core/promiseUtils.js";import{watch as l,initial as u}from"../../core/reactiveUtils.js";import{property as c,subclass as d}from"../../core/accessorSupport/decorators.js";import{UpdatingHandles as m}from"../../core/support/UpdatingHandles.js";import p from"../../geometry/Point.js";import{polygonToVolume as f}from"./focusAreaUtils.js";import{ElevationContext as h}from"./layers/graphics/ElevationContext.js";import{FocusAreaColorNode as g}from"./webgl-engine/effects/focusArea/FocusAreaColorNode.js";import{FocusAreaMaskNode as w}from"./webgl-engine/effects/focusArea/FocusAreaMaskNode.js";import{FocusAreaOutlineItem as y}from"./webgl-engine/effects/focusArea/FocusAreaOutlineItem.js";let v=class extends r{get updating(){return this._updatingHandles.updating||!!this._outlineMap?.some(e=>e.updating)}constructor(e){super(e),this._updatingHandles=new m,this._elevationContext=new h,this._previousVolumes=new Map,this._outlineMap=new o}initialize(){this.addHandles([l(()=>({volumes:this.volumes,ready:this.view.groundView?.ready}),({volumes:e,ready:r})=>{this._previousVolumes=e,r&&(0!==e.size&&this._maskRenderNode?.updateGeometries(),this._ensureRenderNodes())},u)]),this._outlineMap=n(()=>this.areas?.areas,e=>new y({area:e,view:this.view}),{recycleItems:!0})}destroy(){this.removeAllHandles(),this._outlineMap.destroy(),this._updatingHandles.destroy()}get areas(){return this.view.map?.focusAreas}get enabledAreas(){return this.areas?.areas.toArray().filter(({enabled:e})=>e)??[]}get style(){return this.areas?.style??"bright"}get polygons(){return this.enabledAreas.reduce((e,r)=>e.concat(r.geometries.toArray()),new Array)}containsGeometry(e){if(0===this.polygons.length)return!0;const r=new p(e);return this.polygons.some(e=>e.contains(r))}get volumes(){const e=this.polygons,r=this._previousVolumes;if(!this.view.renderCoordsHelper||s(Array.from(r?.keys()??[]),e))return r??new Map;const o=new Map;for(const s of e){const e=r?.get(s);if(e)o.set(s,e);else try{const e=f(s,this.view,this._elevationContext);if(null==e)continue;if(a(e)){this._updatingHandles.consumePromise(e);continue}o.set(s,e)}catch(n){i.getLogger(this).error(new t("focusareasview:projection-failed","Failed to project focus area geometry to view spatial reference",{geometry:s,error:n}))}}return o}_ensureRenderNodes(){if(this.view.stage)if(0===this.volumes.size){const{_maskRenderNode:e,_colorRenderNode:r}=this;this._maskRenderNode=this._colorRenderNode=null,r?.fadeOut(()=>{e?.destroy(),r?.destroy()})}else this._maskRenderNode??=new w({focusAreasView:this}),this._colorRenderNode??=new g({focusAreasView:this}),this.view.stage.renderView.requestRender()}};e([c()],v.prototype,"updating",null),e([c({readOnly:!0})],v.prototype,"volumes",null),e([c({constructOnly:!0})],v.prototype,"view",void 0),v=e([d("esri.views.3d.FocusAreasView")],v);export{v as FocusAreasView};
