import{r as t,c as s,h as i,a as e}from"./p-PqnYwNKt.js";const h=".link-wrapper{display:flex;flex-direction:column;align-items:center;gap:8px;margin-top:8px}";const r=class{constructor(i){t(this,i);this.ifxListUpdate=s(this,"ifxListUpdate",7);this.expanded=false;this.showMore=false;this.selectedCount=0;this.totalItems=0;this.name="";this.maxVisibleItems=6;this.type="checkbox";this.internalResetTrigger=false;this.handleMutation=()=>{const t=this.getTotalItems();if(t!==this.totalItems){this.totalItems=t;this.handleCheckedChange()}this.updateListEntriesType(this.type)};this.toggleList=t=>{t.stopPropagation();this.expanded=!this.expanded};this.toggleShowMore=t=>{t.stopPropagation();this.showMore=!this.showMore};this.handleCheckedChange=t=>{if(t&&t.detail.type==="radio-button"&&t.detail.value){const s=Array.from(this.el.querySelectorAll("ifx-list-entry")).filter((s=>s.getAttribute("type")==="radio-button"&&s!==t.target));s.forEach((t=>t.setAttribute("value","false")))}const s=this.getSelectedItems(this.el);this.selectedCount=s.length;this.ifxListUpdate.emit({name:this.name,selectedItems:s})}}handleTypeChange(t){this.updateListEntriesType(t)}resetTriggerChanged(t){if(t){this.reset();this.resetTrigger=false}}componentWillLoad(){this.setupListenersAndObservers();this.initializeList()}disconnectedCallback(){this.cleanupListenersAndObservers()}reset(){this.resetListEntries();this.expanded=false;this.showMore=false;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:true})}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){const s=Array.from(this.el.querySelectorAll("ifx-list-entry"));s.forEach((s=>s.setAttribute("type",t)))}resetListEntries(){const t=Array.from(this.el.querySelectorAll("ifx-list-entry"));t.forEach((t=>{t.value=false;t.setAttribute("value","false")}))}checkRadioButtonConstraint(){if(this.type==="radio-button"&&this.selectedCount>1){this.resetListEntries();this.selectedCount=0}}getTotalItems(){return this.el.querySelectorAll("ifx-list-entry").length}getSelectedItems(t){return Array.from(t.querySelectorAll("ifx-list-entry")).filter((t=>t.getAttribute("value")==="true")).map((t=>({label:t.getAttribute("label"),value:t.getAttribute("value"),type:t.getAttribute("type"),element:t})))}renderList(){const t=Array.from(this.el.querySelectorAll("ifx-list-entry"));const s=this.showMore?t:t.slice(0,this.maxVisibleItems);const e=t.length-s.length;return i("div",{class:"list-wrapper"},s.map((t=>i("slot",{name:t.getAttribute("slot")}))),(e>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:false},this.showMore?"Show less":`Show ${e} more`)))}get el(){return e(this)}static get watchers(){return{type:["handleTypeChange"],resetTrigger:["resetTriggerChanged"]}}};r.style=h;export{r as ifx_list};
//# sourceMappingURL=p-4669e01f.entry.js.map