/*!
 * KoliBri - The accessible HTML-Standard
 */
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});const index=require("./index-277fc2a7.js"),componentNames=require("./component-names-4a2d0b57.js"),dev_utils=require("./dev.utils-0390f767.js"),prop_validators=require("./prop.validators-9c1f1dbd.js"),label=require("./label-5e56f4a8.js"),open=require("./open-10ca3d4d.js"),href=require("./href-a32df224.js");require("./reuse-50a5792c.js"),require("./dev.utils-58fde089.js"),require("./index-6912b26b.js");const validateActive=(e,t,i)=>{prop_validators.watchBoolean(e,"_active",t,i)},KolTreeItemWc=class{constructor(e){index.registerInstance(this,e),this.groupId=`tree-group-${dev_utils.nonce()}`,this.level=void 0,this.state={_active:!1,_hasChildren:!1,_href:"",_label:"",_open:!1},this._active=void 0,this._label=void 0,this._open=void 0,this._href=void 0}render(){const{_href:e,_active:t,_hasChildren:i,_open:a,_label:s}=this.state;return index.h(index.Host,{key:"80b4d8b5633b98cf7ebc12c3c9e50cd5a2617d4a",onSlotchange:this.handleSlotchange.bind(this),class:"kol-tree-item-wc"},index.h("li",{key:"0dc520638d2452cc5687e192300192b22322dd25",class:"tree-item",style:{"--level":`${this.level}`}},index.h(componentNames.KolLinkWcTag,{key:"6cf78c51ec92daaa5d29830eb1e6dd0147c12ee4",class:{"tree-link":!0,"first-level":0===this.level,active:Boolean(t)},_href:e,_label:"",_role:"treeitem",_tabIndex:t?0:-1,_ariaExpanded:i?a:void 0,_ariaOwns:i?this.groupId:void 0,ref:e=>this.linkElement=e},index.h("span",{key:"7681b6f5f59dc63fc025c2e6bf589478cd8e8db2",slot:"expert"},i&&index.h("span",{key:"e2504c3cd286758f562bad3238ded934ef4482f2",class:"toggle-button",onClick:e=>a?void this.handleCollapseClick(e):void this.handleExpandClick(e)},index.h(componentNames.KolIconTag,{key:"892da807da1e116a0c6c6b1566f7db6e087886ff",class:"toggle-button-icon",_icons:"codicon codicon-"+(a?"chevron-down":"chevron-right"),_label:""}))," ",s)),index.h("ul",{key:"45db8c2f2dd4681e7ec0c130df25b0f97c3553ac",hidden:!i||!a,role:"group",id:this.groupId},index.h("slot",{key:"3052b7252e4188563fb2253a738421a3238da9a3"}))))}validateActive(e){validateActive(this,e||!1)}validateLabel(e){label.validateLabel(this,e)}validateOpen(e){open.validateOpen(this,e)}validateHref(e){href.validateHref(this,e)}componentWillLoad(){this.validateActive(this._active),this.validateLabel(this._label),this.validateOpen(this._open),this.validateHref(this._href),this.checkForChildren(),this.determineTreeItemDepth()}determineTreeItemDepth(){let e=0,t=this.host.parentNode.host.parentNode;for(;null!==t&&t.tagName.toLowerCase()!==componentNames.KolTreeTag&&t!==document.body;)t=t.parentElement,e+=1;this.level=e}handleSlotchange(){this.checkForChildren()}checkForChildren(){var e,t;this.state=Object.assign(Object.assign({},this.state),{_hasChildren:Boolean(null===(t=null===(e=this.host.querySelector("slot"))||void 0===e?void 0:e.assignedElements)||void 0===t?void 0:t.call(e).length)})}async focusLink(){await this.linkElement.kolFocus()}async handleExpandClick(e){e.preventDefault(),await this.linkElement.kolFocus(),await this.expand()}async expand(){this.state._hasChildren&&(this.state=Object.assign(Object.assign({},this.state),{_open:!0}))}async handleCollapseClick(e){e.preventDefault(),this.linkElement.focus(),await this.collapse()}async collapse(){this.state._hasChildren&&(this.state=Object.assign(Object.assign({},this.state),{_open:!1}))}async isOpen(){var e;return null!==(e=this.state._open)&&void 0!==e&&e}get host(){return index.getElement(this)}static get watchers(){return{_active:["validateActive"],_label:["validateLabel"],_open:["validateOpen"],_href:["validateHref"]}}};exports.kol_tree_item_wc=KolTreeItemWc;