/* COPYRIGHT Esri - https://js.arcgis.com/5.1.0/LICENSE.txt */
import{__decorate as i}from"tslib";import e from"../../../../Color.js";import t from"../../../../core/Accessor.js";import{isSome as s}from"../../../../core/arrayUtils.js";import{makeHandle as r,destroyHandle as o}from"../../../../core/handleUtils.js";import{watch as h,syncAndInitial as p}from"../../../../core/reactiveUtils.js";import{property as a,subclass as l}from"../../../../core/accessorSupport/decorators.js";import{initializeProjection as n,project as c}from"../../../../geometry/projectionUtils.js";import{GraphicsCollection as g}from"../../../../support/GraphicsCollection.js";import m from"../../../../symbols/SimpleFillSymbol.js";import d from"../../../../symbols/SimpleLineSymbol.js";import u from"../../../../symbols/SimpleMarkerSymbol.js";import{getHighlightGraphics as y}from"../../../layers/support/highlightUtils.js";let w=class extends t{get updating(){return this.graphicsView?.updating??!1}constructor(i){super(i),this._highlightCounts=new Map,this._graphicsViewLoader=null,this.graphics=new g,this.graphicsView=null,this.suspended=!1;const t=new e([255,255,255,1/255]);this._symbols=new Map([["point",new u({size:"2px",style:"square",color:t})],["polyline",new d({width:"2px",color:t})],["polygon",new m({outline:null,color:t})]])}highlight(i,e){const t=y(i);if(0===t.length)return r();let s,o=!1;return this.updatingHandles.consumePromise(Promise.all([this._createHighlightGraphics(t),this._ensureGraphicsView3D()]).then(([i,t])=>{!o&&t&&(s=this._addHighlightGraphics(t,i,e))})),r(()=>{o=!0,s?.remove()})}preload(){this._ensureGraphicsView3D()}_addHighlightGraphics(i,e,t){for(const r of e)this._highlightCounts.set(r,(this._highlightCounts.get(r)??0)+1);this.graphics.addMany(e);const s=i.highlight(e,t);return r(()=>{this._removeHighlightGraphics(e),s.remove()})}_removeHighlightGraphics(i){this.graphics.removeMany(i.filter(i=>{const e=Math.max(0,(this._highlightCounts.get(i)??0)-1);return 0===e?(this._highlightCounts.delete(i),!0):(this._highlightCounts.set(i,e),!1)}))}async _ensureGraphicsView3D(){if(this.graphicsView)return this.graphicsView;this._graphicsViewLoader||(this._graphicsViewLoader=import("../GraphicsView3D.js"));const{default:i}=await this._graphicsViewLoader;if(this.destroyed)return null;const e=new i({view:this.view,layer:{type:"graphics-view-3d-dummy",id:this.layer.id,uid:this.layer.uid,elevationInfo:{mode:"on-the-ground"}},getGraphics:()=>this.graphics,drapeSourcePriorityOffset:.5});return this._set("graphicsView",e),this.addHandles([o(this.graphicsView),h(()=>this.suspended,i=>{e.suspended=i},p)]),e}async _createHighlightGraphics(i){const e=i.map(({geometry:i})=>i?.spatialReference).filter(s).reduce((i,e)=>(0!==i.length&&i.at(-1)?.equals(e)||i.push(e),i),[]),t=this.view.spatialReference,r=e.map(i=>({source:i,dest:t}));try{await n(r)}catch{return[]}return i.map(i=>{const{geometry:e}=i;try{const s=e?c(e,t):null,r=i.cloneShallow();return r.geometry=s,r.symbol=this._symbols.get(s?.type),r}catch{return i}})}};i([a()],w.prototype,"graphics",void 0),i([a()],w.prototype,"graphicsView",void 0),i([a()],w.prototype,"view",void 0),i([a()],w.prototype,"layer",void 0),i([a()],w.prototype,"updatingHandles",void 0),i([a()],w.prototype,"suspended",void 0),i([a()],w.prototype,"updating",null),w=i([l("esri.views.3d.layers.support.ImageHighlightHelper3D")],w);export{w as ImageHighlightHelper3D};
