/*!
 * KoliBri - The accessible HTML-Standard
 */
import{r as registerInstance,h,H as Host,g as getElement}from"./index-b2c61df0.js";import{g as KolIconTag,n as KolLinkWcTag,y as KolTreeTag}from"./component-names-068dc2ae.js";import{n as nonce}from"./dev.utils-a14ff412.js";import{b as watchBoolean}from"./prop.validators-db70e3c4.js";import{v as validateLabel}from"./label-20475610.js";import{v as validateOpen}from"./open-5b527658.js";import{v as validateHref}from"./href-74f1c87f.js";import"./reuse-b66836de.js";import"./dev.utils-1ca991a2.js";import"./index-db4aa6e4.js";const validateActive=(e,t,a)=>{watchBoolean(e,"_active",t,a)},KolTreeItemWc=class{constructor(e){registerInstance(this,e),this.groupId=`tree-group-${nonce()}`,this.renderIcon=e=>h(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:a,_open:i,_label:s}=this.state;return h(Host,{key:"a7478410c633314ba5b7a9e8588b5b9484efeb94",onSlotchange:this.handleSlotchange.bind(this),class:"kol-tree-item-wc"},h("li",{key:"6c3ad7b0e013ec83d92f0d05a222d0696aa98729",class:"tree-item",style:{"--level":`${this.level}`}},h(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:i,_ariaOwns:a?this.groupId:void 0,ref:e=>this.linkElement=e},h("span",{key:"361d16b78885085be82c83e6fe4b8bd83e8274d7",slot:"expert"},a&&h("span",{key:"3a742c6ea9fa940854cb21f1607ab0490c091558",class:"toggle-button",onClick:e=>i?void this.handleCollapseClick(e):void this.handleExpandClick(e)},this.renderIcon({icon:"codicon codicon-"+(i?"chevron-down":"chevron-right"),label:i?"Vorschläge öffnen":"Vorschläge schließen"}))," ",s)),h("ul",{key:"087a87f28d8f06d72cee95f9ab553f7f79e16496",hidden:!a||!i,role:"group",id:this.groupId},h("slot",{key:"8e286b2265806859a9bd61809c6387331df607f3"}))))}validateActive(e){validateActive(this,e||!1)}validateLabel(e){validateLabel(this,e)}validateOpen(e){validateOpen(this,e)}validateHref(e){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()!==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 getElement(this)}static get watchers(){return{_active:["validateActive"],_label:["validateLabel"],_open:["validateOpen"],_href:["validateHref"]}}};export{KolTreeItemWc as kol_tree_item_wc};