/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.24/esri/copyright.txt for details.
*/
define(["../chunks/_rollupPluginBabelHelpers","../chunks/tslib.es6","./Collection","./HandleOwner","./maybe","./has","./Error","./Logger","./accessorSupport/watch","./accessorSupport/trackingUtils","./accessorSupport/decorators/property","./arrayUtils","./accessorSupport/ensureType","./accessorSupport/decorators/subclass"],(function(t,e,o,r,i,s,n,c,l,u,a,p,h,d){"use strict";let f=function(e){function r(t){var o;return(o=e.call(this,t)||this).getCollections=null,o}t._inheritsLoose(r,e);var s=r.prototype;return s.initialize=function(){this.handles.add(u.autorun((()=>this._refresh())))},s.destroy=function(){this.getCollections=null},s._refresh=function(){const t=i.isSome(this.getCollections)?this.getCollections():null;if(i.isNone(t))return void this.removeAll();let e=0;for(const o of t)i.isSome(o)&&(e=this._processCollection(e,o));this.splice(e,this.length)},s._createNewInstance=function(t){return new o(t)},s._processCollection=function(t,e){if(!e)return t;const o=this.itemFilterFunction?this.itemFilterFunction:t=>!!t;for(const r of e)if(r){if(o(r)){const e=this.indexOf(r,t);e>=0?e!==t&&this.reorder(r,t):this.add(r,t),++t}if(this.getChildrenFunction){const e=this.getChildrenFunction(r);if(Array.isArray(e))for(const o of e)t=this._processCollection(t,o);else t=this._processCollection(t,e)}}return t},r}(r.HandleOwnerMixin(o));e.__decorate([a.property()],f.prototype,"getCollections",void 0),e.__decorate([a.property()],f.prototype,"getChildrenFunction",void 0),e.__decorate([a.property()],f.prototype,"itemFilterFunction",void 0),f=e.__decorate([d.subclass("esri.core.CollectionFlattener")],f);return f}));
