/* COPYRIGHT Esri - https://js.arcgis.com/5.1.2/LICENSE.txt */
import{__decorate as e}from"tslib";import t from"../Collection.js";import{castForReferenceSetter as o,referenceSetter as s}from"../collectionUtils.js";import"../has.js";import"../Logger.js";import{subclass as r}from"../accessorSupport/decorators.js";import{property as i}from"../accessorSupport/decorators/property.js";let n=class extends t{constructor(e){super(e),this.addHandles([this.on("before-add",e=>{null==e.item&&e.preventDefault()}),this.on("after-add",e=>this._own(e.item)),this.on("after-remove",e=>this._release(e.item))])}get owner(){return this._get("owner")}set owner(e){this.destroyed||e!==this._get("owner")&&(this._releaseAll(),this._set("owner",e),this._ownAll())}_ownAll(){for(const e of this.items)this._own(e)}_releaseAll(){for(const e of this.items)this._release(e)}_createNewInstance(e){return this.itemType?new(t.ofType(this.itemType.Type))(e):new t(e)}};function l(e,t){return{type:e,cast:o,set(o){const r=s(o,this._get(t),e);r&&!r.destroyed&&(r.owner=this),this._set(t,r)}}}e([i()],n.prototype,"owner",null),n=e([r("esri.core.support.OwningCollection")],n);export{n as OwningCollection,l as owningCollectionProperty};
