/* COPYRIGHT Esri - https://js.arcgis.com/5.1.0/LICENSE.txt */
import{isDeleteItem as t,isAddAttachmentItem as e,isDeleteAttachmentItem as a,isModifyAttachmentItem as s,isAddItem as r,isModifyItem as h}from"./ApplySetItem.js";class p{constructor(){this.applyItems=new Map,this.featureState=null}get items(){return[...this.applyItems.values()]}get deleteItems(){return this.items.filter(t)}_add(t){this.applyItems.set(t.featureChangeId,t)}revert(){this.featureState?.clearAll(),this.applyItems.clear()}push(p){if(e(p))return void this._add(p);const i=this.applyItems.get(p.featureChangeId);i?(r(i)&&t(p)&&(this.applyItems.delete(i.featureChangeId),this.featureState?.removeLocalState(i)),r(i)&&h(p)&&(i.graphic=p.graphic,this.featureState?.updateLocalState(i)),h(i)&&t(p)&&(this.applyItems.delete(i.featureChangeId),p.graphic=i.revertGraphic,this._add(p),this.featureState?.removeLocalState(i),this.featureState?.applyLocalState(p)),h(i)&&h(p)&&(i.graphic=p.graphic,this.featureState?.updateLocalState(i)),s(i)&&a(p)&&(this.applyItems.delete(i.featureChangeId),this._add(p)),s(i)&&s(p)&&(i.attachmentData=p.attachmentData)):(this._add(p),a(p)||s(p)||this.featureState?.applyLocalState(p))}remove(t){this.applyItems.has(t.featureChangeId)&&(this.applyItems.delete(t.featureChangeId),e(t)||a(t)||s(t)||this.featureState&&this.featureState.removeLocalState(t))}}export{p as ApplySet};
