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