import{r,h as l,i as d,H as h,ak as o,g as c,m as v}from"./index-B6uGkrgD.js";import{I as _}from"./component-N8_W7bhu-Q1tppvIJ.js";import{v as b}from"./href-BtQW7uxb-Bgmw_m7U.js";import{v as f}from"./label-Cw7rCjUo-YeMVw3_3.js";import{v as m}from"./open-BhLtfnQI-DzhCf8hh.js";import{c as p}from"./clsx-COFh-Vc8-D7cYsJM5.js";import{n as u}from"./dev.utils-98sTB6ui-O8z9q0jz.js";import"./tslib.es6-CxX45GIN-BGVaTf34.js";const k=(e,t,a)=>{v(e,"_active",t,a)},T=class{constructor(e){r(this,e),this.groupId=`tree-group-${u()}`,this.state={_active:!1,_hasChildren:!1,_href:"",_label:"",_open:!1}}render(){const{_href:e,_active:t,_hasChildren:a,_open:i,_label:n}=this.state;return l(h,{key:"84779b44b60d29ae2a4336a1c769d7339b0205ba",onSlotchange:this.handleSlotchange.bind(this)},l("li",{key:"d703da510e3406b8a303795fc93b46b30c2bdce1",class:"kol-tree-item",style:{"--level":`${this.level}`}},l(d,{key:"abaee288fee504151843e9de6c9c992f57c6cd8e",class:p("kol-tree-item__link",{"kol-tree-item__link--first-level":this.level===0,"kol-tree-item__link--active":t}),_href:e,_label:"",_role:"treeitem",_tabIndex:t?0:-1,_ariaExpanded:a?i:void 0,_ariaOwns:a?this.groupId:void 0,ref:s=>this.linkElement=s},l("span",{key:"7ec7b0cd425a889e8c45dbdedec8b8c479fb2e83",class:"kol-tree-item__link-inner",slot:"expert"},a?l("span",{class:"kol-tree-item__toggle-button",onClick:s=>i?void this.handleCollapseClick(s):void this.handleExpandClick(s)},l(_,{class:"kol-tree-item__toggle-button-icon",icons:`kolicon kolicon-${i?"chevron-down":"chevron-right"}`,label:""})):l("span",{class:"kol-tree-item__toggle-button-placeholder"}),l("span",{key:"4b99e88bbb624c5af2f1984561ee3aee63f89be9",class:"kol-tree-item__text"},n))),l("ul",{key:"2033da37082e68b37e59d87ca6166c65708eaaf7",class:"kol-tree-item__children",hidden:!a||!i,role:"group",id:this.groupId},l("slot",{key:"ab4032f2a472db8135267b1eac2374bfe8b5efc8"}))))}validateActive(e){k(this,e||!1)}validateLabel(e){f(this,e)}validateOpen(e){m(this,e)}validateHref(e){b(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 a=0,i=(t=(e=this.host)===null||e===void 0?void 0:e.parentNode)===null||t===void 0?void 0:t.host.parentNode;for(;i!==null&&i.tagName.toLowerCase()!==o&&i!==document.body;)i=i.parentElement,a+=1;this.level=a}handleSlotchange(){this.checkForChildren()}checkForChildren(){var e,t,a;this.state=Object.assign(Object.assign({},this.state),{_hasChildren:!!(!((a=(t=(e=this.host)===null||e===void 0?void 0:e.querySelector("slot"))===null||t===void 0?void 0:t.assignedElements)===null||a===void 0)&&a.call(t).length)})}getTreeParent(){var e,t;let a=this.host;for(;a;){const i=a.closest(o);if(i){const s=(e=i.shadowRoot)===null||e===void 0?void 0:e.querySelector("kol-tree-wc");return s||void 0}const n=(t=a.getRootNode())===null||t===void 0?void 0:t.host;if(!n||n===document.body)break;a=n.parentElement}}async focus(){if(this.host&&this.linkElement)return Promise.resolve(this.linkElement.focus())}async handleExpandClick(e){e.preventDefault(),this.host&&this.linkElement&&await this.linkElement.focus(),await this.expand()}async expand(){var e,t;this.state._hasChildren&&(this.state=Object.assign(Object.assign({},this.state),{_open:!0}),(t=(e=this.getTreeParent())===null||e===void 0?void 0:e.invalidateOpenItemsCache)===null||t===void 0||t.call(e))}async handleCollapseClick(e){e.preventDefault(),this.host&&this.linkElement&&await this.linkElement.focus(),await this.collapse()}async collapse(){var e,t;this.state._hasChildren&&(this.state=Object.assign(Object.assign({},this.state),{_open:!1}),(t=(e=this.getTreeParent())===null||e===void 0?void 0:e.invalidateOpenItemsCache)===null||t===void 0||t.call(e))}async isOpen(){var e;return(e=this.state._open)!==null&&e!==void 0?e:!1}get host(){return c(this)}static get watchers(){return{_active:["validateActive"],_label:["validateLabel"],_open:["validateOpen"],_href:["validateHref"]}}};export{T as kol_tree_item_wc};
//# sourceMappingURL=kol-tree-item-wc.entry-CL_wmlve.js.map
