import{r,h as l,e as h,H as c,aj as o,g as d,l as v}from"./index-Di6F0tPl.js";import{I as _}from"./component-BoywdBMh-ec-3NjvW.js";import{v as f}from"./href-COBxk7m0-C1RW1gwB.js";import{v as p}from"./label-vxVEH2gH-D6YJvZ98.js";import{v as m}from"./open-BMZVrISI-Cydl0Q-X.js";import{c as b}from"./clsx-COFh-Vc8-D7cYsJM5.js";import{n as u}from"./dev.utils-B-ZwZYpj-C6NlZA9W.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(c,{key:"99f8d3ba0603c5d5a434a6e625cf66a3649eb7c7",onSlotchange:this.handleSlotchange.bind(this)},l("li",{key:"b654e4ca72a1fe5270bebe60432ff7eab929fcb3",class:"kol-tree-item",style:{"--level":`${this.level}`}},l(h,{key:"54283f511b4a63d692f381318c37a46898bac377",class:b("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:"45e7d7a7db4b0db77f17b2090a87ab1c717ef88a",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:"e8ea0d05e8ce655948a4cfbf464205c5434f15b8",class:"kol-tree-item__text"},n))),l("ul",{key:"38eb21a4037ce603e3ef4a6a7ec289337aa5fe9e",class:"kol-tree-item__children",hidden:!a||!i,role:"group",id:this.groupId},l("slot",{key:"c626e2a6074fef982423f19310d0a536cd4831f6"}))))}validateActive(e){k(this,e||!1)}validateLabel(e){p(this,e)}validateOpen(e){m(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(){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 d(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-DogOU8kO.js.map
