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 ObservableSet extends(i(t)){[Symbol.toStringTag]="ObservableSet";get size(){return this._originalSet.size}_originalSet;constructor(){super(),this._originalSet=new Set}add(t){return this.has(t)||(this._originalSet.add(t),e(this,"size"),this.emit("after-add",{item:t,target:this}),this.emit("change",{added:[t],removed:[],moved:[],target:this})),this}addMany(t){const i=[];for(const e of t)this.has(e)||(i.push(e),this._originalSet.add(e));if(i.length){if(e(this,"size"),this.hasEventListener("after-add"))for(const t of i)this.emit("after-add",{item:t,target:this});this.emit("change",{added:i,removed:[],moved:[],target:this})}return this}clear(){if(!this.size)return;const t=Array.from(this.values());if(this._originalSet.clear(),e(this,"size"),this.hasEventListener("after-remove"))for(const e of t)this.emit("after-remove",{item:e,target:this});this.emit("change",{added:[],removed:t,moved:[],target:this})}delete(t){return!!this.has(t)&&(this._originalSet.delete(t),e(this,"size"),this.emit("after-remove",{item:t,target:this}),this.emit("change",{added:[],removed:[t],moved:[],target:this}),!0)}deleteMany(t){const i=[];for(const e of t)this.has(e)&&(i.push(e),this._originalSet.delete(e));if(i.length){if(e(this,"size"),this.hasEventListener("after-remove"))for(const t of i)this.emit("after-remove",{item:t,target:this});this.emit("change",{added:[],removed:i,moved:[],target:this})}return!!i.length}forEach(t,e){this._originalSet.forEach(t,e)}has(t){return this._originalSet.has(t)}entries(){return this._originalSet.entries()}keys(){return this._originalSet.keys()}values(){return this._originalSet.values()}[Symbol.iterator](){return this._originalSet[Symbol.iterator]()}toJSON(){return r([...this.values()])}}