/*
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","../../core/Collection","../../core/collectionUtils","../../core/maybe","../../core/reactiveUtils","../../core/accessorSupport/decorators/property","../../core/arrayUtils","../../core/has","../../core/accessorSupport/ensureType","../../core/accessorSupport/decorators/subclass","./LayerView"],(function(i,e,s,r,t,l,a,n,y,o,h,c){"use strict";let u=function(e){function a(i){var r;return(r=e.call(this,i)||this).type="group",r.layerViews=new s,r}i._inheritsLoose(a,e);var n=a.prototype;return n._allLayerViewVisibility=function(i){this.layerViews.forEach((e=>{e.visible=i}))},n.initialize=function(){this.handles.add([this.layerViews.on("change",(i=>this._layerViewsChangeHandler(i))),l.watch((()=>this.layer.visibilityMode),(()=>this._applyVisibility((()=>this._allLayerViewVisibility(this.visible)),(()=>this._applyExclusiveVisibility(null)))),l.sync),l.watch((()=>this.visible),(i=>{this._applyVisibility((()=>this._allLayerViewVisibility(i)),(()=>{}))}),l.sync)],"grouplayerview"),this._layerViewsChangeHandler({target:null,added:this.layerViews.toArray(),removed:[],moved:[]})},n.isUpdating=function(){return this.layerViews.some((i=>i.updating))},n._hasLayerViewVisibleOverrides=function(){return this.layerViews.some((i=>i._isOverridden("visible")))},n._findLayerViewForLayer=function(i){return i&&this.layerViews.find((e=>e.layer===i))},n._firstVisibleOnLayerOrder=function(){const i=this.layer.layers.find((i=>{const e=this._findLayerViewForLayer(i);return null==e?void 0:e.visible}));return i&&this._findLayerViewForLayer(i)},n._applyExclusiveVisibility=function(i){t.isNone(i)&&(i=this._firstVisibleOnLayerOrder(),t.isNone(i)&&this.layerViews.length>0&&(i=this._findLayerViewForLayer(this.layer.layers.getItemAt(0)))),this.layerViews.forEach((e=>{e.visible=e===i}))},n._layerViewsChangeHandler=function(i){this.handles.remove("grouplayerview:visible"),this.handles.add(this.layerViews.map((i=>l.watch((()=>i.visible),(e=>this._applyVisibility((()=>{e!==this.visible&&(i.visible=this.visible)}),(()=>this._applyExclusiveVisibility(e?i:null)))),l.sync))).toArray(),"grouplayerview:visible");const e=i.added[i.added.length-1];this._applyVisibility((()=>this._allLayerViewVisibility(this.visible)),(()=>this._applyExclusiveVisibility(null!=e&&e.visible?e:null)))},n._applyVisibility=function(i,e){var s,r;this._hasLayerViewVisibleOverrides()&&("inherited"===(null==(s=this.layer)?void 0:s.visibilityMode)?i():"exclusive"===(null==(r=this.layer)?void 0:r.visibilityMode)&&e())},i._createClass(a,[{key:"layerViews",set:function(i){this._set("layerViews",r.referenceSetter(i,this._get("layerViews")))}},{key:"updatingProgress",get:function(){return 0===this.layerViews.length?1:this.layerViews.reduce(((i,e)=>i+e.updatingProgress),0)/this.layerViews.length}}]),a}(c);e.__decorate([a.property({cast:r.castForReferenceSetter})],u.prototype,"layerViews",null),e.__decorate([a.property({readOnly:!0})],u.prototype,"updatingProgress",null),e.__decorate([a.property()],u.prototype,"view",void 0),u=e.__decorate([h.subclass("esri.views.layers.GroupLayerView")],u);return u}));
