/*!
 * KoliBri - The accessible HTML-Standard
 */
import{r as e,h as t,H as i,g as s}from"./index-5d2ba3a9.js";import{j as a,g as l,x as n}from"./component-names-6ca7e863.js";import{n as o}from"./dev.utils-7df45d9a.js";import{b as h}from"./prop.validators-64749272.js";import{v as c}from"./label-e8ec0e3a.js";import{v as d}from"./open-7e16be6b.js";import{v as r}from"./href-cec41fcd.js";import"./reuse-32931294.js";import"./dev.utils-fab45cbc.js";import"./index-da3e0c00.js";const f=(e,t,a)=>{h(e,"_active",t,a)},b=class{constructor(t){e(this,t),this.groupId=`tree-group-${o()}`,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:s,_hasChildren:o,_open:n,_label:h}=this.state;return t(i,{key:"ceb601f2530ae6d55fe0a136905b084acb3a58c4",onSlotchange:this.handleSlotchange.bind(this),class:"kol-tree-item-wc"},t("li",{key:"cf961136786ddbf84b69485240b2ad564fdd3344",class:"tree-item",style:{"--level":`${this.level}`}},t(a,{key:"6b2fef9321edbacad56337a59ff24e7f00faa02c",class:{"tree-link":!0,"first-level":0===this.level,active:Boolean(s)},_href:e,_label:"",_role:"treeitem",_tabIndex:s?0:-1,_ariaExpanded:o?n:void 0,_ariaOwns:o?this.groupId:void 0,ref:e=>this.linkElement=e},t("span",{key:"3d1e9682b93daf10ce9f39708af6ab3651e61fa5",class:"tree-link-inner",slot:"expert"},o?t("span",{class:"toggle-button",onClick:e=>n?void this.handleCollapseClick(e):void this.handleExpandClick(e)},t(l,{class:"toggle-button-icon",_icons:"codicon codicon-"+(n?"chevron-down":"chevron-right"),_label:""})):t("span",{class:"toggle-button-placeholder"}),h)),t("ul",{key:"0741b2c611b922a51702ca680e5190c8a6d28e57",hidden:!o||!n,role:"group",id:this.groupId},t("slot",{key:"9e0d50a5cf017c4d63b022baf00db787305e797a"}))))}validateActive(e){f(this,e||!1)}validateLabel(e){c(this,e)}validateOpen(e){d(this,e)}validateHref(e){r(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(){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 s(this)}static get watchers(){return{_active:["validateActive"],_label:["validateLabel"],_open:["validateOpen"],_href:["validateHref"]}}};export{b as kol_tree_item_wc};