/*!
 * KoliBri - The accessible HTML-Standard
 */
import{r as e,h as t,H as i,g as s}from"./index-91489a9f.js";import{f as a,d as l,q as d}from"./component-names-a18a51c8.js";import{n}from"./dev.utils-b9e6a3e1.js";import{c as o}from"./clsx-09a06a12.js";import{b as c}from"./prop.validators-9feb1d92.js";import{v as h}from"./label-d0315384.js";import{v as r}from"./open-20d08415.js";import{v as f}from"./href-d8ec67f8.js";import"./reuse-32931294.js";import"./dev.utils-fab45cbc.js";import"./index-da3e0c00.js";const b=(e,t,a)=>{c(e,"_active",t,a)},_=class{constructor(t){e(this,t),this.groupId=`tree-group-${n()}`,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:n,_open:d,_label:r}=this.state;return t(i,{key:"e8cebee52ed0f115c3aa30e82e2e3ccf5d09e626",onSlotchange:this.handleSlotchange.bind(this)},t("li",{key:"c4b1d56ae69f55ca57ad8d863df02fe0d7ff4f00",class:"kol-tree-item",style:{"--level":`${this.level}`}},t(a,{key:"8e87e00dae2d0e6dcad5602e28b5642bc31702f5",class:o("kol-tree-item__link",{"kol-tree-item__link--first-level":0===this.level,"kol-tree-item__link--active":s}),_href:e,_label:"",_role:"treeitem",_tabIndex:s?0:-1,_ariaExpanded:n?d:void 0,_ariaOwns:n?this.groupId:void 0,ref:e=>this.linkElement=e},t("span",{key:"f037767f3e0142ec622d5e3dc03f303b30831abf",slot:"expert"},n&&t("span",{key:"a344ded5e01b484b686aeb71b4370fe37f3fd8b1",class:"kol-tree-item__toggle-button",onClick:e=>d?void this.handleCollapseClick(e):void this.handleExpandClick(e)},t(l,{key:"d84793747ce43c28fca27abde4c76f4a5feb060b",class:"kol-tree-item__toggle-button-icon",_icons:"codicon codicon-"+(d?"chevron-down":"chevron-right"),_label:""}))," ",r)),t("ul",{key:"828ff0900dc3f9018e939ef0d519cdcabbab652b",class:"kol-tree-item__children",hidden:!n||!d,role:"group",id:this.groupId},t("slot",{key:"7fd8f3b71eb060d42835e3d1b311ab4bb7930f99"}))))}validateActive(e){b(this,e||!1)}validateLabel(e){h(this,e)}validateOpen(e){r(this,e)}validateHref(e){f(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()!==d&&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{_ as kol_tree_item_wc};