/*
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/reactiveUtils","../../../core/accessorSupport/decorators/property","../../../core/arrayUtils","../../../core/has","../../../core/accessorSupport/ensureType","../../../core/accessorSupport/decorators/subclass","../../Widget","../support/LayerTreeNode","../../support/widgetUtils","../../support/jsxFactory"],(function(e,i,s,t,o,l,n,r,a,c,d,h){"use strict";var g;const p={expand:"expand",collapse:"collapse",hideSublayer:"hideSublayer",showSublayer:"showSublayer"},u="esri-building-disciplines-tree-node",b={base:`${u}`,root:`${u}--root`,leaf:`${u}--leaf`,label:`${u}__label`,checkbox:`${u}__checkbox`,checkboxChecked:`${u}__checkbox--checked esri-icon-check-mark`,checkboxIndeterminate:`${u}__checkbox--indeterminate esri-icon-minus`,collapseToggle:`${u}__collapse-toggle esri-icon-right`,collapseToggleCollapsed:`${u}__collapse-toggle--collapsed`,children:`${u}__children`,level:e=>`${u}--level-${e}`};let _=g=function(i){function t(e){var s;return(s=i.call(this,e)||this).messages=p,s.toggleSiblingsVisibility=!1,s._childWidgets=[],s._updateChildWidgets=()=>{s._destroyChildWidgets(),s._childWidgets=s.node.children.toArray().reverse().map((e=>new g({node:e,messages:s.messages,toggleSiblingsVisibility:s.toggleSiblingsVisibility})))},s}e._inheritsLoose(t,i);var o=t.prototype;return o.initialize=function(){this.own([s.on((()=>this.node.children),"after-changes",this._updateChildWidgets,{onListenerAdd:this._updateChildWidgets,onListenerRemove:this._updateChildWidgets}),s.watch((()=>[this.messages,this.toggleSiblingsVisibility]),this._updateChildWidgets,s.initial)])},o.destroy=function(){this._destroyChildWidgets()},o.render=function(){const e=this.node,i=e.isRoot,s=e.isLeaf;return e.isDiscipline&&s?null:h.tsx("div",{key:e.id,class:this.classes(b.base,b.level(e.level),{[b.root]:i,[b.leaf]:s}),bind:this,onkeydown:this._onKeydown,tabIndex:s?null:0,role:"treeitem","aria-expanded":e.collapsed?"false":"true"},h.tsx("label",{bind:this,class:b.label,onclick:this._onCheckboxToggle},this._renderCollapseToggle(),this._renderCheckbox(),h.tsx("span",null,e.title)),this._renderChildren(e))},o._renderCheckbox=function(){var e,i;const s=this.node.visible,t=!0===s,o=null===s,l=t?null==(e=this.messages)?void 0:e.hideSublayer:null==(i=this.messages)?void 0:i.showSublayer;return h.tsx("button",{bind:this,class:this.classes(b.checkbox,{[b.checkboxChecked]:t,[b.checkboxIndeterminate]:o}),onclick:this._onCheckboxToggle,role:"checkbox","aria-checked":t?"true":"false","aria-label":l,title:l,type:"button"})},o._renderCollapseToggle=function(){var e,i;if(!this.node.hasChildren)return null;const s=this.node.collapsed,t=s?null==(e=this.messages)?void 0:e.expand:null==(i=this.messages)?void 0:i.collapse;return h.tsx("div",{bind:this,class:this.classes(b.collapseToggle,{[b.collapseToggleCollapsed]:s}),onclick:this._onCollapseToggle,"aria-label":t,title:t})},o._renderChildren=function(e){return!e.hasChildren||e.collapsed?null:h.tsx("div",{class:b.children},this._childWidgets.map((e=>e.render())))},o._onKeydown=function(e){switch(e.key){case"Space":case"Enter":if(!e.target.classList.contains(b.base))return;e.stopPropagation(),this.node.toggleVisibility();break;case"ArrowLeft":e.stopPropagation(),this.node.toggleCollapsed(!d.isRTL(this.container));break;case"ArrowRight":e.stopPropagation(),this.node.toggleCollapsed(!!d.isRTL(this.container))}},o._onCheckboxToggle=function(e){e.preventDefault(),e.stopPropagation();(e.metaKey||e.ctrlKey)&&this.toggleSiblingsVisibility?this.node.toggleAllSiblingsVisibility():this.node.toggleVisibility()},o._onCollapseToggle=function(e){e.preventDefault(),e.stopPropagation(),this.node.toggleCollapsed()},o._destroyChildWidgets=function(){this._childWidgets.forEach((e=>e.destroy())),this._childWidgets=[]},t}(a);i.__decorate([t.property({type:c.LayerTreeNode})],_.prototype,"node",void 0),i.__decorate([t.property()],_.prototype,"messages",void 0),i.__decorate([t.property({nonNullable:!0})],_.prototype,"toggleSiblingsVisibility",void 0),i.__decorate([t.property()],_.prototype,"_childWidgets",void 0),_=g=i.__decorate([r.subclass("esri.widgets.BuildingExplorer.BuildingDisciplinesTree.BuildingDisciplinesNode")],_);return _}));
