import{r as t,c as e,a as s,h as i}from"./p-wX3eJOEL.js";const r=class{constructor(s){t(this,s),this.ifxListUpdate=e(this,"ifxListUpdate",7)}get el(){return s(this)}expanded=!1;showMore=!1;selectedCount=0;totalItems=0;name="";maxVisibleItems=6;type="checkbox";resetTrigger;internalResetTrigger=!1;ifxListUpdate;observer;handleTypeChange(t){this.updateListEntriesType(t)}resetTriggerChanged(t){t&&(this.reset(),this.resetTrigger=!1)}componentWillLoad(){this.setupListenersAndObservers(),this.initializeList()}disconnectedCallback(){this.cleanupListenersAndObservers()}reset(){this.resetListEntries(),this.expanded=!1,this.showMore=!1,this.selectedCount=0,this.ifxListUpdate.emit({name:this.name,selectedItems:[]})}render(){return this.renderList()}setupListenersAndObservers(){this.el.addEventListener("ifxListEntryChange",this.handleCheckedChange),this.observer=new MutationObserver(this.handleMutation),this.observer.observe(this.el,{childList:!0})}cleanupListenersAndObservers(){this.el.removeEventListener("ifxListEntryChange",this.handleCheckedChange),this.observer.disconnect()}initializeList(){this.selectedCount=this.getSelectedItems(this.el).length,this.totalItems=this.getTotalItems(),this.updateListEntriesType(this.type),this.checkRadioButtonConstraint()}updateListEntriesType(t){Array.from(this.el.querySelectorAll("ifx-list-entry")).forEach((e=>e.setAttribute("type",t)))}resetListEntries(){Array.from(this.el.querySelectorAll("ifx-list-entry")).forEach((t=>{t.value=!1,t.setAttribute("value","false")}))}handleMutation=()=>{const t=this.getTotalItems();t!==this.totalItems&&(this.totalItems=t,this.handleCheckedChange()),this.updateListEntriesType(this.type)};checkRadioButtonConstraint(){"radio-button"===this.type&&this.selectedCount>1&&(this.resetListEntries(),this.selectedCount=0)}getTotalItems(){return this.el.querySelectorAll("ifx-list-entry").length}toggleShowMore=t=>{t.stopPropagation(),this.showMore=!this.showMore};getSelectedItems(t){return Array.from(t.querySelectorAll("ifx-list-entry")).filter((t=>"true"===t.getAttribute("value"))).map((t=>({label:t.getAttribute("label"),value:t.getAttribute("value"),type:t.getAttribute("type"),element:t})))}handleCheckedChange=t=>{t&&"radio-button"===t.detail.type&&t.detail.value&&Array.from(this.el.querySelectorAll("ifx-list-entry")).filter((e=>"radio-button"===e.getAttribute("type")&&e!==t.target)).forEach((t=>t.setAttribute("value","false")));const e=this.getSelectedItems(this.el);this.selectedCount=e.length,this.ifxListUpdate.emit({name:this.name,selectedItems:e})};renderList(){const t=Array.from(this.el.querySelectorAll("ifx-list-entry")),e=this.showMore?t:t.slice(0,this.maxVisibleItems),s=t.length-e.length;return i("div",{class:"list-wrapper"},e.map((t=>i("slot",{name:t.getAttribute("slot")}))),(s>0||this.showMore)&&i("div",{class:"link-wrapper",onClick:this.toggleShowMore},i("ifx-icon",{key:this.showMore.toString(),icon:this.showMore?"chevron-up-16":"chevron-down-16"}),i("ifx-link",{size:"s",href:"",target:"_blank",variant:"underlined",disabled:!1},this.showMore?"Show less":`Show ${s} more`)))}static get watchers(){return{type:[{handleTypeChange:0}],resetTrigger:[{resetTriggerChanged:0}]}}};r.style=".link-wrapper{display:flex;flex-direction:column;align-items:center;gap:8px;margin-top:8px}";export{r as ifx_list}