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