/*!
 * KoliBri - The accessible HTML-Standard
 */
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});const index=require("./index-5cf289dd.js"),componentNames=require("./component-names-b370a3a3.js"),dev_utils=require("./dev.utils-cf2db529.js"),prop_validators=require("./prop.validators-476ef807.js"),label=require("./label-c3e352c8.js"),open=require("./open-b72a9d97.js"),href=require("./href-54273ea2.js");require("./reuse-daa2baf3.js"),require("./dev.utils-3e595d38.js"),require("./index-1285d2d1.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.renderIcon=e=>index.h(componentNames.KolIconTag,{class:"toggle-button-icon",_label:e.label,_icons:e.icon}),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:"a7478410c633314ba5b7a9e8588b5b9484efeb94",onSlotchange:this.handleSlotchange.bind(this),class:"kol-tree-item-wc"},index.h("li",{key:"6c3ad7b0e013ec83d92f0d05a222d0696aa98729",class:"tree-item",style:{"--level":`${this.level}`}},index.h(componentNames.KolLinkWcTag,{key:"fbd0b31027e032f6df61652df29a0b37ef67a104",class:{"tree-link":!0,"first-level":0===this.level,active:Boolean(t)},_href:e,_label:"",_role:"treeitem",_tabIndex:t?0:-1,_ariaExpanded:a,_ariaOwns:i?this.groupId:void 0,ref:e=>this.linkElement=e},index.h("span",{key:"361d16b78885085be82c83e6fe4b8bd83e8274d7",slot:"expert"},i&&index.h("span",{key:"3a742c6ea9fa940854cb21f1607ab0490c091558",class:"toggle-button",onClick:e=>a?void this.handleCollapseClick(e):void this.handleExpandClick(e)},this.renderIcon({icon:"codicon codicon-"+(a?"chevron-down":"chevron-right"),label:a?"Vorschläge öffnen":"Vorschläge schließen"}))," ",s)),index.h("ul",{key:"087a87f28d8f06d72cee95f9ab553f7f79e16496",hidden:!i||!a,role:"group",id:this.groupId},index.h("slot",{key:"8e286b2265806859a9bd61809c6387331df607f3"}))))}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(){this.linkElement.focus()}async handleExpandClick(e){e.preventDefault(),this.linkElement.focus(),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;