import{Evented as t}from"@arcgis/core/core/Evented.js";import{notifyChange as e,observable as i}from"../support/observableUtils.js";import{toJSON as r}from"./object.js";export class ObservableMap extends(i(t)){[Symbol.toStringTag]="ObservableMap";get size(){return this._originalMap.size}_originalMap;constructor(){super(),this._originalMap=new Map}clear(){if(!this.size)return;const t=Array.from(this.entries());if(this._originalMap.clear(),e(this,"size"),this.hasEventListener("after-remove"))for(const[e,i]of t)this.emit("after-remove",{item:[e,i],target:this});this.emit("change",{added:[],removed:t,target:this})}delete(t){if(!this.has(t))return!1;const i=this.get(t);return this._originalMap.delete(t),e(this,"size"),this.emit("after-remove",{item:[t,i],target:this}),this.emit("change",{added:[],removed:[[t,i]],target:this}),!0}forEach(t,e){this._originalMap.forEach(t,e)}get(t){return this._originalMap.get(t)}has(t){return this._originalMap.has(t)}set(t,i){const r=!this.has(t),s=this.get(t);return this._originalMap.set(t,i),e(this,"size"),r||this.emit("after-remove",{item:[t,s],target:this}),this.emit("after-add",{item:[t,i],target:this}),this.emit("change",{added:[[t,i]],removed:r?[]:[[t,s]],target:this}),this}entries(){return this._originalMap.entries()}keys(){return this._originalMap.keys()}values(){return this._originalMap.values()}[Symbol.iterator](){return this._originalMap[Symbol.iterator]()}toJSON(){return r([...this])}}