/* COPYRIGHT Esri - https://js.arcgis.com/5.1.0/LICENSE.txt */
import e from"./Accessor.js";import{handlesGroup as t,makeHandle as s}from"./handleUtils.js";const n=e=>{const n=e;class r extends n{constructor(){super(...arguments),this._listenersMap=null}clearEvents(){this._listenersMap?.clear(),this._listenersMap=null}destroy(){this.clearEvents()}emit(e,t){let s=this._listenersMap?.get(e);if(!s)return!1;let n=!1;for(const r of s.slice()){const e="deref"in r?r.deref():r;e?e?.call(this,t):n=!0}return n&&(s=s.filter(e=>!("deref"in e)||null!=e.deref()),this._listenersMap.set(e,s)),s.length>0}on(e,n){if(Array.isArray(e)){const s=e.map(e=>this.on(e,n));return t(s)}if(e.includes(","))throw new TypeError("Evented.on() with a comma delimited string of event types is not supported");this._listenersMap??=new Map;const r=this._listenersMap.get(e)||[];return r.push(n),this._listenersMap.set(e,r),s(()=>{const t=this._listenersMap?.get(e),s=t?.indexOf(n)??-1;s>=0&&t.splice(s,1)})}once(e,t){const s=this.on(e,e=>{s.remove();const n="deref"in t?t.deref():t;n?.call(null,e)});return s}hasEventListener(e){const t=this._listenersMap?.get(e);return null!=t&&t.length>0}}return r},r=n(class{}),i=r,l=n(e);export{i as EventEmitter,r as Evented,l as EventedAccessor,n as EventedMixin};
