import{p as t,H as e,c as s,h as i,t as r}from"./p-Bpcl2TqF.js";import{d as n}from"./p-KvSIaMXJ.js";import{d as a}from"./p-D9XRTfuC.js";const h=()=>`.link-wrapper{display:flex;flex-direction:column;align-items:center;gap:8px;margin-top:8px}`;const l=t(class t extends e{constructor(t){super();if(t!==false){this.__registerHost()}this.__attachShadow();this.ifxListUpdate=s(this,"ifxListUpdate",7)}get el(){return 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}]}}static get style(){return h()}},[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]},undefined,{type:[{handleTypeChange:0}],resetTrigger:[{resetTriggerChanged:0}]}]);function o(){if(typeof customElements==="undefined"){return}const t=["ifx-list","ifx-icon","ifx-link"];t.forEach((t=>{switch(t){case"ifx-list":if(!customElements.get(r(t))){customElements.define(r(t),l)}break;case"ifx-icon":if(!customElements.get(r(t))){n()}break;case"ifx-link":if(!customElements.get(r(t))){a()}break}}))}const c=l;const f=o;export{c as IfxList,f as defineCustomElement};
//# sourceMappingURL=ifx-list.js.map