/* COPYRIGHT Esri - https://js.arcgis.com/5.1.2/LICENSE.txt */
import{Evented as e}from"../../../core/Evented.js";import{findInMap as t,someMap as r}from"../../../core/MapUtils.js";class s extends e{constructor(){super(...arguments),this._map=new Map}clear(){if(this._map.size>0){const e=this.toArray();this._map.clear(),this.emit("change",{added:[],removed:e})}}get length(){return this._map.size}get(e){return this._map.get(e)}addMany(e){if(0===e.length)return;const t=new Set;for(let s=0;s<e.length;s++){const r=e[s],o=r.objectId,n=this._map.get(o);n?(t.add(o),r!==n&&(e[s]=n),n.refCount||(n.refCount=0),++n.refCount):(r.refCount=1,this._map.set(o,r))}const r=t.size>0?e.filter(e=>!t.has(e.objectId)):e;r.length>0&&this.emit("change",{added:r,removed:[]})}removeMany(e){const t=[];for(const r of e){const e=r.objectId,s=this._map.get(e);null!=s&&(!s.refCount||--s.refCount<=0)&&(this._map.delete(e),t.push(r))}t.length>0&&this.emit("change",{added:[],removed:t})}removeManyByObjectId(e){const t=[];for(const r of e){const e=this._map.get(r);null!=e&&(!e.refCount||--e.refCount<=0)&&(this._map.delete(r),t.push(e))}t.length>0&&this.emit("change",{added:[],removed:t})}toArray(){return[...this._map.values()]}find(e){return t(this._map,e)}some(e){return r(this._map,e)}forEach(e){this._map.forEach(t=>e(t))}}export{s as GraphicsMap};
