import{p as t,H as e,c as s,h as i,t as r}from"./p-CHfEnK-2.js";import{d as n}from"./p-B5hDbbCP.js";import{d as h}from"./p-CUljqVvL.js";const a=t(class extends e{constructor(t){super(),!1!==t&&this.__registerHost(),this.__attachShadow(),this.ifxListUpdate=s(this,"ifxListUpdate",7)}get el(){return 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,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}]}}static get style(){return".link-wrapper{display:flex;flex-direction:column;align-items:center;gap:8px;margin-top:8px}"}},[769,"ifx-list",{name:[1],maxVisibleItems:[2,"max-visible-items"],type:[1],resetTrigger:[1028,"reset-trigger"],expanded:[32],showMore:[32],selectedCount:[32],totalItems:[32],internalResetTrigger:[32]},void 0,{type:[{handleTypeChange:0}],resetTrigger:[{resetTriggerChanged:0}]}]),l=a,o=function(){"undefined"!=typeof customElements&&["ifx-list","ifx-icon","ifx-link"].forEach((t=>{switch(t){case"ifx-list":customElements.get(r(t))||customElements.define(r(t),a);break;case"ifx-icon":customElements.get(r(t))||n();break;case"ifx-link":customElements.get(r(t))||h()}}))};export{l as IfxList,o as defineCustomElement}