import{r as e,c as t,a as i,h as s,d as a}from"./p-wX3eJOEL.js";const l=class{constructor(i){e(this,i),this.ifxTopbarFilterChange=t(this,"ifxTopbarFilterChange",7)}get el(){return i(this)}selectedOptions=[];ifxTopbarFilterChange;showAllFilters=!1;maxShownFilters=4;visibleSlots;async showMoreFilters(e){this.showAllFilters=e,this.updateVisibleSlots()}connectedCallback(){this.el.addEventListener("ifxFilterSelect",this.handleTopbarFilterChange),this.el.addEventListener("ifxFilterSearchChange",this.handleSearchChange),window.addEventListener("ifxResetFiltersEvent",this.handleResetEvent)}disconnectedCallback(){this.el.removeEventListener("ifxFilterSelect",this.handleTopbarFilterChange),this.el.removeEventListener("ifxFilterSearchChange",this.handleSearchChange),window.removeEventListener("ifxResetFiltersEvent",this.handleResetEvent)}componentWillLoad(){this.updateVisibleSlots()}updateVisibleSlots(){this.visibleSlots=this.showAllFilters?Number.MAX_SAFE_INTEGER:this.maxShownFilters}handleFilterButtonsClick=e=>{this.showMoreFilters(e)};handleResetEvent=()=>{const e=this.el.shadowRoot?.querySelector('slot[name="filter-search"]');e instanceof HTMLSlotElement&&e.assignedElements({flatten:!0}).forEach((e=>{const t=e.querySelector("ifx-filter-search").shadowRoot.querySelectorAll("ifx-search-field");t.length>0&&t.forEach((e=>{e.value=""}))})),this.selectedOptions=[],this.ifxTopbarFilterChange.emit(this.selectedOptions)};handleSearchChange=e=>{this.handleTopbarFilterChange(e)};handleTopbarFilterChange=e=>{const t=[...this.selectedOptions];if("ifxFilterSearchChange"===e.type){const{filterName:i,filterValue:s}=e.detail,a=t.findIndex((e=>e.filterName===i));-1!==a?t[a].filterValues=[s]:t.push({filterName:i,filterValues:[s],type:"text"})}else if("ifxFilterSelect"===e.type){const{filterName:i,filterValues:s,type:a}=e.detail,l=t.findIndex((e=>e.filterName===i));-1!==l?(t[l].filterValues=s,t[l].type=a):t.push({filterName:i,filterValues:s,type:a})}this.selectedOptions=t,this.ifxTopbarFilterChange.emit(this.selectedOptions)};render(){const e=Math.max(0,this.visibleSlots),t=this.el.querySelectorAll("ifx-set-filter").length,i=Math.min(e,t,Number.MAX_SAFE_INTEGER),l=Array.from({length:i},((e,t)=>s("div",{class:"filter-slot-wrapper"},s("slot",{name:`filter-component-${t+1}`}))));return s(a,{key:"ffe2a8fb921554af84679eb8653d79b13f86c8b1"},s("div",{key:"ff836ffc5399fc087dc4aab78ef6521fdf9c919d",class:"search-container"},s("slot",{key:"8490ebe5747f37ed476adcc3f63b406435778376",name:"filter-search"})," "),s("div",{key:"4d3960b70ebfbcf0e65df544b1bc22006447d3ef",class:"components-container"},l.length>0?l:s("slot",{name:"filter-component"}),this.showMoreFilters&&s("div",{key:"9265bc7f1d60b341be4cc997023e7fa671c73c8e",class:"filter-buttons-wrapper",onClick:()=>this.handleFilterButtonsClick(!this.showAllFilters)},s("ifx-button",{key:"a5fad6269fc27513177b172dfb668d56bf32ddab",type:"button",disabled:!1,variant:"tertiary",size:"m",target:"_blank",theme:"default","full-width":"false"},s("ifx-icon",{key:"3287ca74ece70905d275f41a74cb54f9a30a8162",icon:"filter-16"}),this.showAllFilters?"Less filters":"More filters"))))}};l.style=":host{display:block;width:100%}.search-container{display:flex;width:calc(100% - 48px);padding-left:24px;padding-right:24px;flex-direction:row;align-items:flex-start;margin-bottom:16px}.components-container{display:flex;width:calc(100% - 48px);padding-left:24px;padding-right:24px;flex-direction:row;align-items:flex-end;align-content:flex-end;flex-wrap:wrap;gap:16px}.filter-slot-wrapper{flex-grow:1;flex-basis:100%;max-width:100%}@media (max-width: 1024px){.filter-buttons-wrapper{order:3;width:100%;display:flex;justify-content:center;padding-top:16px;}}@media (min-width: 720px) and (max-width: 1024px){.filter-slot-wrapper{flex-basis:calc((100% - 16px) / 2);max-width:calc((100% - 16px) / 2)}}@media (min-width: 1025px){.filter-slot-wrapper{flex-basis:auto;max-width:200px}::slotted([slot=filter-search]){max-width:828px}}::slotted([slot=filter-search]){flex-grow:1;flex-basis:100%;width:100%}";export{l as ifx_filter_bar}