import o from"@arcgis/core/core/Collection";import{CollectionProxy as i}from"./CollectionProxy.js";import{checkArg as t}from"./checkArg.js";export class CopyOnWriteCollection extends i{_originalCollection;get originalCollection(){return this._originalCollection}set originalCollection(o){t("value",o).isNotMissing(),this.isModified||(this._collection=o),this._originalCollection=o}get isModified(){return this._collection!==this.originalCollection}constructor(o){super(o),t("collection",o).isNotMissing(),this._originalCollection=o}clone(){const o=new CopyOnWriteCollection(this.originalCollection);return this.isModified&&(o._collection=this._cloneCollection(this._collection)),o}add(o,i){return this._copy(),super.add(o,i)}removeAt(o){return this._copy(),super.removeAt(o)}reorder(o,i){return this._copy(),super.reorder(o,i)}reset(){this.isModified&&(this._collection=this._originalCollection)}sort(o){return this._copy(),super.sort(o)}_copy(){this.isModified||(this._collection=this._cloneCollection(this.originalCollection))}_cloneCollection(i){return new o(i.toArray())}}