import{r as o,h as a,j as r,i as c,H as h,an as d,g as _,n as v}from"./index-DpEJCboz.js";import{v as p}from"./href-BtQW7uxb-DN_AqcUL.js";import{v as f}from"./label-C18ud7Yt-CZ4vFVQv.js";import{v as b}from"./open-BhLtfnQI-CM7QyOkl.js";import{c as m}from"./clsx-COFh-Vc8-D7cYsJM5.js";import{n as k}from"./dev.utils-khfgdH9Q-PvIox5H6.js";const u=(e,t,l)=>{v(e,"_active",t,l)},E=class{constructor(e){o(this,e),this.groupId=`tree-group-${k()}`,this.state={_active:!1,_hasChildren:!1,_href:"",_label:"",_open:!1}}render(){const{_href:e,_active:t,_hasChildren:l,_open:i,_label:n}=this.state;return a(h,{key:"6ed9a47b4b73d14e696c145550cfaa988fd317e5",onSlotchange:this.handleSlotchange.bind(this)},a("li",{key:"3fbaa347c0b01103169880822e8669934f218577",class:"kol-tree-item",style:{"--level":`${this.level}`}},a(r,{key:"52863b0ae00641041422606750d956b5507bc46c",class:m("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:l?i:void 0,_ariaOwns:l?this.groupId:void 0,ref:s=>this.linkElement=s},a("span",{key:"be106d194e17645551d0644c4bdb2523e8071ee2",class:"kol-tree-item__link-inner",slot:"expert"},l?a("span",{class:"kol-tree-item__toggle-button",onClick:s=>i?void this.handleCollapseClick(s):void this.handleExpandClick(s)},a(c,{class:"kol-tree-item__toggle-button-icon",_icons:`kolicon kolicon-${i?"chevron-down":"chevron-right"}`,_label:""})):a("span",{class:"kol-tree-item__toggle-button-placeholder"}),a("span",{key:"c2b944199a8268567fba31c70fa5546f4d7f71d3",class:"kol-tree-item__text"},n))),a("ul",{key:"9956ed829cc7a535441358169134aac3e7c7b3fb",class:"kol-tree-item__children",hidden:!l||!i,role:"group",id:this.groupId},a("slot",{key:"8dbb7f03eefc65991f8cb326daec64b5a2f59728"}))))}validateActive(e){u(this,e||!1)}validateLabel(e){f(this,e)}validateOpen(e){b(this,e)}validateHref(e){p(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(;t!==null&&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:!!(!((t=(e=this.host.querySelector("slot"))===null||e===void 0?void 0:e.assignedElements)===null||t===void 0)&&t.call(e).length)})}async focus(){var e;return Promise.resolve((e=this.linkElement)===null||e===void 0?void 0:e.focus())}async handleExpandClick(e){var t;e.preventDefault(),await((t=this.linkElement)===null||t===void 0?void 0:t.focus()),await this.expand()}async expand(){this.state._hasChildren&&(this.state=Object.assign(Object.assign({},this.state),{_open:!0}))}async handleCollapseClick(e){var t;e.preventDefault(),await((t=this.linkElement)===null||t===void 0?void 0:t.focus()),await this.collapse()}async collapse(){this.state._hasChildren&&(this.state=Object.assign(Object.assign({},this.state),{_open:!1}))}async isOpen(){var e;return(e=this.state._open)!==null&&e!==void 0?e:!1}get host(){return _(this)}static get watchers(){return{_active:["validateActive"],_label:["validateLabel"],_open:["validateOpen"],_href:["validateHref"]}}};export{E as kol_tree_item_wc};
//# sourceMappingURL=kol-tree-item-wc.entry-D6zceiap.js.map
