/* COPYRIGHT Esri - https://js.arcgis.com/5.0/LICENSE.txt */
import{__decorate as i}from"tslib";import e from"../../../core/Accessor.js";import t from"../../../core/Collection.js";import{watch as l,initial as s}from"../../../core/reactiveUtils.js";import{property as r,subclass as o}from"../../../core/accessorSupport/decorators.js";let n=class extends e{constructor(i){super(i),this.id="root",this.parent=null,this.children=new t,this.layers=new t,this.level=0,this._childIds=new Set,this._layerUniqueIds=new Set}initialize(){this.addHandles([this.layers.on("before-add",i=>{this._layerUniqueIds.has(i.item.uid)?i.preventDefault():this._layerUniqueIds.add(i.item.uid)}),this.layers.on("after-add",({item:i})=>{this.addHandles([l(()=>i.visible,()=>this.notifyChange("visible"),s),l(()=>i.title,()=>this.notifyChange("title"),s)],i.uid)}),this.layers.on("before-remove",({item:i})=>{this.removeHandles(i.uid),this.notifyChange("title"),this.notifyChange("visible")}),this.children.on("before-add",i=>{this._childIds.has(i.item.id)?i.preventDefault():(i.item._set("parent",this),this._childIds.add(i.item.id))})])}destroy(){this.children.forEach(i=>i.destroy())}get hasChildren(){return this.children.length>0}get isDiscipline(){return 1===this.level}get visible(){return d(this.layers,i=>i.visible)}get title(){return d(this.layers,i=>i.title)||this.layers.items.map(i=>i.title).join(", ")||null}toggleVisibility(i){const e=void 0===i?!this.visible:i;this.layers.forEach(i=>{i.visible=e}),e&&null!=this.parent&&this.parent.toggleVisibility(!0)}toggleAllSiblingsVisibility(i){const e=void 0===i?!this.visible:i;this.toggleVisibility(e),null!=this.parent&&(this.parent.toggleVisibility(e),this.parent.children.forEach(i=>i.toggleVisibility(e)))}};function d(i,e){let t=null;for(const l of i.items){const i=e(l);if(null!=t&&t!==i)return null;t=i}return t}i([r({nonNullable:!0})],n.prototype,"id",void 0),i([r()],n.prototype,"parent",void 0),i([r({nonNullable:!0,readOnly:!0})],n.prototype,"children",void 0),i([r({nonNullable:!0,readOnly:!0})],n.prototype,"layers",void 0),i([r({nonNullable:!0})],n.prototype,"level",void 0),i([r({readOnly:!0})],n.prototype,"hasChildren",null),i([r({readOnly:!0})],n.prototype,"isDiscipline",null),i([r({readOnly:!0})],n.prototype,"visible",null),i([r({readOnly:!0})],n.prototype,"title",null),n=i([o("esri.widgets.BuildingExplorer.support.LayerTreeNode")],n);export{n as LayerTreeNode};
