/*!
 * KoliBri - The accessible HTML-Standard
 */
import{r as e,h as t,H as i,g as a}from"./index-a0b4dca2.js";import{g as s,d as l,v as n}from"./component-names-aa3cbc3c.js";import{n as c}from"./dev.utils-5d039f3c.js";import{b as d}from"./prop.validators-c5e6ad2d.js";import{v as o}from"./label-d70e7c34.js";import{v as h}from"./open-f7031548.js";import{v as r}from"./href-31b01f08.js";import"./reuse-32931294.js";import"./dev.utils-fab45cbc.js";import"./index-541b643a.js";const f=(e,t,a)=>{d(e,"_active",t,a)},b=class{constructor(t){e(this,t),this.groupId=`tree-group-${c()}`,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:o,_open:n,_label:c}=this.state;return t(i,{key:"4364cb19591055058e8893714c9a6deaf0afdad1",onSlotchange:this.handleSlotchange.bind(this),class:"kol-tree-item-wc"},t("li",{key:"ad5d8a8054180d0bdec565fb1b2101045f7d343f",class:"tree-item",style:{"--level":`${this.level}`}},t(s,{key:"901f2bc989fde2687e115056a67c6548ebbcc157",class:{"tree-link":!0,"first-level":0===this.level,active:Boolean(a)},_href:e,_label:"",_role:"treeitem",_tabIndex:a?0:-1,_ariaExpanded:o?n:void 0,_ariaOwns:o?this.groupId:void 0,ref:e=>this.linkElement=e},t("span",{key:"9870cc6ece0861216dc44fd9a24f6ad878dee8a5",slot:"expert"},o&&t("span",{key:"8d07da1ca25ea86118c8eac6400b46029137a544",class:"toggle-button",onClick:e=>n?void this.handleCollapseClick(e):void this.handleExpandClick(e)},t(l,{key:"95649317f4685ed2c46bb30feb65325e4125ab9b",class:"toggle-button-icon",_icons:"codicon codicon-"+(n?"chevron-down":"chevron-right"),_label:""}))," ",c)),t("ul",{key:"c9f1633a0884483d4a050d3c87b071a9ac179d22",hidden:!o||!n,role:"group",id:this.groupId},t("slot",{key:"67dda157773837ab70455a9457ca4ca8b783e532"}))))}validateActive(e){f(this,e||!1)}validateLabel(e){o(this,e)}validateOpen(e){h(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 a(this)}static get watchers(){return{_active:["validateActive"],_label:["validateLabel"],_open:["validateOpen"],_href:["validateHref"]}}};export{b as kol_tree_item_wc};