/* COPYRIGHT Esri - https://js.arcgis.com/5.0/LICENSE.txt */
import{c as u}from"./EH5576ZY.js";import{y as h}from"./GRFF5Y4R.js";var i=class o{constructor(){this._groups=new Map}destroy(){this.removeAll()}add(r,s){if(Array.isArray(r)){let e=this._getOrCreateGroup(s);for(let t of r)this._isHandle(t)&&e.push(t)}else this._isHandle(r)&&this._getOrCreateGroup(s).push(r);return this}forEach(r,s){if(typeof r=="function")this._groups.forEach(e=>e.forEach(r));else{let e=this._getGroup(r);e&&s&&e.forEach(s)}}has(r){return this._groups.has(this._ensureGroupKey(r))}remove(r){if(typeof r!="string"&&Array.isArray(r)){for(let s of r)this.remove(s);return this}return this.has(r)?(this._removeAllFromGroup(this._getGroup(r)),this._groups.delete(this._ensureGroupKey(r)),this):this}removeAll(){return this._groups.forEach(r=>this._removeAllFromGroup(r)),this._groups.clear(),this}_isHandle(r){return r&&(!!r.remove||r instanceof o)}_getOrCreateGroup(r){if(this.has(r))return this._getGroup(r);let s=[];return this._groups.set(this._ensureGroupKey(r),s),s}_getGroup(r){return this._groups.get(this._ensureGroupKey(r))}_ensureGroupKey(r){return r||"_default_"}_removeAllFromGroup(r){for(let s of r)s instanceof o?s.removeAll():s.remove()}},n=class extends h{constructor(r){super(),this.destroyed=!1,r==="disconnect"?this.onDisconnected(()=>this.removeAllHandles()):this.onDestroy(()=>this.destroy())}addHandles(r,s){if(this.destroyed){let e=Array.isArray(r)?r:[r];for(let t of e)t.remove();return}this._handles??=new i,this._handles.add(r,s)}removeHandles(r){this._handles?.remove(r)}removeAllHandles(){this._handles?.removeAll()}destroy(){this.destroyed=!0,this.removeAllHandles()}hasHandles(r){return this._handles?.has(r)??!1}},l=u(n);export{l as a};
