/* COPYRIGHT Esri - https://js.arcgis.com/5.0/LICENSE.txt */
import{removeUnordered as t}from"../../../../core/arrayUtils.js";import{makeHandle as e}from"../../../../core/handleUtils.js";import{getOrCreateMapValue as i}from"../../../../core/MapUtils.js";class h{constructor(t){this.highlightName=t,this.ids=new Set}}class s{constructor({collection:t,forAllFeatures:e,forAllFeaturesOfNode:i}){this._highlights=new Map,this._collection=t,this._forAllFeatures=e,this._forAllFeaturesOfNode=i}destroy(){this._highlights.forEach(t=>t.forEach(t=>this._releaseSet(t))),this._highlights=null}acquireSet(s){const l=new h(s);i(this._highlights,s,()=>[]).push(l);const o=e(()=>{const e=this._highlights?.get(s);e&&(this._releaseSet(l),t(e,l))});return{set:l,handle:o}}setFeatureIds(t,e){e.forEach(e=>t.ids.add(e)),this._initializeSet(t)}_initializeSet(t){this._forAllFeatures((e,i,h)=>(t.ids.has(e)&&this._collection.addComponentHighlight(h.objectHandle,i,t.highlightName),0))}_releaseSet(t){this._forAllFeatures((e,i,h)=>(t.ids.has(e)&&this._collection.removeComponentHighlight(h.objectHandle,i,t.highlightName),0))}objectCreated(t){this._highlights.forEach((e,i)=>{e.forEach(e=>{this._forAllFeaturesOfNode(t,(h,s)=>(e.ids.has(h)&&this._collection.addComponentHighlight(t.objectHandle,s,i),0))})})}objectDeleted(t){this._collection.clearHighlights(t.objectHandle)}}export{s as default};
