/*!
 * KoliBri - The accessible HTML-Standard
 */
import{r as e,h as t,H as i,g as s}from"./index-Brmny3Vg.js";import{c as l,u as a}from"./component-names-Dy77vq43.js";import{I as o}from"./component-DHo2YdSx.js";import{e as n}from"./common-DEEjER7G.js";import{v as r}from"./href-yQN98Z4F.js";import{v as d}from"./label-Cg7TG_7b.js";import{v as h}from"./open-Djbpz6kg.js";import{c}from"./clsx-COFh-Vc8.js";import{c as v}from"./dev.utils-HhhlYW_9.js";import"./tslib.es6-QNbPBOk5.js";import"./bem-registry-B9CzNnO1.js";const f=(e,t,i)=>{n(e,"_active",t,i)};const _=class{constructor(t){e(this,t);this.groupId=v("tree-group");this.state={_active:false,_hasChildren:false,_href:"",_label:"",_open:false}}render(){const{_href:e,_active:s,_hasChildren:a,_open:n,_label:r}=this.state;return t(i,{key:"5dafc8516e71c4908d468b8844b0e765d1cba71a",onSlotchange:this.handleSlotchange.bind(this)},t("li",{key:"b050361b08edf953c60cda62bce3c716528d19ca",class:"kol-tree-item",style:{"--level":`${this.level}`}},t(l,{key:"5575f3158d9adbb566f75ec7687d83f1b84a8935",class:c("kol-tree-item__link",{"kol-tree-item__link--first-level":this.level===0,"kol-tree-item__link--active":s}),_href:e,_label:"",_role:"treeitem",_tabIndex:s?0:-1,_ariaExpanded:a?n:undefined,_ariaOwns:a?this.groupId:undefined,ref:e=>this.linkElement=e},t("span",{key:"f64170d2888e773e1649252efac509108c92ebe6",class:"kol-tree-item__link-inner",slot:"expert"},a?t("span",{class:"kol-tree-item__toggle-button",onClick:e=>n?void this.handleCollapseClick(e):void this.handleExpandClick(e)},t(o,{class:"kol-tree-item__toggle-button-icon",icons:`kolicon kolicon-${n?"chevron-down":"chevron-right"}`,label:""})):t("span",{class:"kol-tree-item__toggle-button-placeholder"}),t("span",{key:"02eeae533f9c27fb1d34856ef83dc54b0472abb4",class:"kol-tree-item__text"},r))),t("ul",{key:"fdfad19b37792ed8efed76b6e9b7bf977ee7d6cb",class:"kol-tree-item__children",hidden:!a||!n,role:"group",id:this.groupId},t("slot",{key:"eba7b5f9a6ee173a12d67238195d5c5fd34f38b4"}))))}validateActive(e){f(this,e||false)}validateLabel(e){d(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(){var e,t;let i=0;let s=(t=(e=this.host)===null||e===void 0?void 0:e.parentNode)===null||t===void 0?void 0:t.host.parentNode;while(s!==null&&s.tagName.toLowerCase()!==a&&s!==document.body){s=s.parentElement;i+=1}this.level=i}handleSlotchange(){this.checkForChildren()}checkForChildren(){var e,t,i;this.state=Object.assign(Object.assign({},this.state),{_hasChildren:Boolean((i=(t=(e=this.host)===null||e===void 0?void 0:e.querySelector("slot"))===null||t===void 0?void 0:t.assignedElements)===null||i===void 0?void 0:i.call(t).length)})}getTreeParent(){var e,t;let i=this.host;while(i){const s=i.closest(a);if(s){const t=(e=s.shadowRoot)===null||e===void 0?void 0:e.querySelector("kol-tree-wc");if(t){return t}return undefined}const l=(t=i.getRootNode())===null||t===void 0?void 0:t.host;if(!l||l===document.body){break}i=l.parentElement}return undefined}async focus(e){if(this.host&&this.linkElement){return this.linkElement.focus(e)}}async handleExpandClick(e){e.preventDefault();if(this.host&&this.linkElement){await this.linkElement.focus()}await this.expand()}async expand(){var e,t;if(this.state._hasChildren){this.state=Object.assign(Object.assign({},this.state),{_open:true});void((t=(e=this.getTreeParent())===null||e===void 0?void 0:e.invalidateOpenItemsCache)===null||t===void 0?void 0:t.call(e))}}async handleCollapseClick(e){e.preventDefault();if(this.host&&this.linkElement){await this.linkElement.focus()}await this.collapse()}async collapse(){var e,t;if(this.state._hasChildren){this.state=Object.assign(Object.assign({},this.state),{_open:false});void((t=(e=this.getTreeParent())===null||e===void 0?void 0:e.invalidateOpenItemsCache)===null||t===void 0?void 0:t.call(e))}}async isOpen(){var e;return(e=this.state._open)!==null&&e!==void 0?e:false}get host(){return s(this)}static get watchers(){return{_active:["validateActive"],_label:["validateLabel"],_open:["validateOpen"],_href:["validateHref"]}}};export{_ as kol_tree_item_wc};
//# sourceMappingURL=kol-tree-item-wc.entry.js.map