import{I as x,af as O,k as R,aG as D,m as I,_ as N,r as h,o as i,b as c,n as r,p as f,l as u,u as d,v as g,a as w,q as o,F as k,e as v,f as E,t as z,w as B,aE as V}from"./main-BDtKGhFI.js";import{C as G,F as L}from"./FacetsSelectionFi-D2gIuEVQ.js";const P={name:"FacetsMenuFi",components:{ClearAllFacetsFi:G,FacetsSelectionFi:L,IconFi:x,SelectFi:O},mixins:[R,D],props:{facets:{type:Array,required:!0},allowClearAll:{type:Boolean,default:!0},centered:{type:Boolean,default:!1},chipsCentered:{type:Boolean,default:!1},showClearAll:{type:Boolean,default:!0},columnsMax:{type:Number,default:6}},emits:["change","clear-all-facets"],data(){return{notMounted:!0,showFacetsMobile:!1,leavingFacetsMobile:!1,openFacet:null,showFilters:!1,isClosing:!1,isOpening:!1,facetsStyle:{}}},computed:{...I({windowDimensions:"layout/getWindowDimensions"}),maxFacetsInRow(){return this.isXL?this.columnsMax:this.isLG?4:6},nonHiddenFacets(){return this.facets.filter(e=>!e.noMenu)},compactedFacets(){return this.nonHiddenFacets.slice(0,this.maxFacetsInRow)},displayedFacets(){return this.showFilters||!this.isSM?this.nonHiddenFacets:this.compactedFacets},selectedElements(){const e=[];return this.facets.forEach(n=>{n.elements.forEach(s=>{s.selected&&e.push({facet:n,element:s})})}),e},showMobileResultButton(){var e;return!this.isSM&&((e=this.selectedElements)==null?void 0:e.length)},centeredSpace(){return(12-12/this.columnsMax*this.displayedFacets.length)/2+1}},watch:{"facets.length":async function(){this.showFilters&&(await this.$nextTick(),this.setFacetsMaxHeight())},windowDimensions:{deep:!0,handler(){this.resize()}}},mounted(){this.notMounted=!1},methods:{registerDomElement(e){this.collapseToFacet=e},clearAllFacets(){this.$emit("clear-all-facets")},openMobileFacets(){this.bodyDisableScroll(),this.showFacetsMobile=!0},async closeMobileFacets(){this.leavingFacetsMobile=!0,await new Promise(e=>{setTimeout(e,300)}),this.bodyEnableScroll(),this.showFacetsMobile=!1,this.leavingFacetsMobile=!1},setFacetsMaxHeight(){if(this.notMounted)return;const{height:e}=this.$refs.selectedFacets.getBoundingClientRect();this.facetsStyle={"max-height":`${e}px`}},async toggleFacets(){var n;if(!((n=this.$refs)!=null&&n.facets)&&!this.collapseToFacet){this.showFilters=!this.showFilters;return}const e=()=>{const s=this.collapseToFacet||this.$refs.facets[0].$el,{height:M}=s.getBoundingClientRect(),l=s.currentStyle||window.getComputedStyle(s);return{"max-height":`${M+parseFloat(l.marginBottom)}px`}};this.togglingFrom=this.showFilters,this.showFilters?(this.setFacetsMaxHeight(),this.isClosing=!0,await this.$nextTick(),this.facetsStyle=e(),await new Promise(s=>{setTimeout(s,300)}),this.showFilters=!1,this.isClosing=!1,this.facetsStyle={}):(this.facetsStyle=e(),this.showFilters=!0,this.isOpening=!0,this.$refs.selectedFacets&&(await this.$nextTick(),this.setFacetsMaxHeight(),await new Promise(s=>{setTimeout(s,300)})),this.isOpening=!1)},toggleOpen(e){this.openFacet===e.name?this.openFacet=null:this.openFacet=e.name},close(e){this.openFacet===e.name&&(this.openFacet=null)},change(...e){this.$emit("change",...e)},resize(){this.isSM&&this.bodyEnableScroll()}}},q={key:0,class:"facets-menu-fi__mobile-filter-header"},W={class:"facets-menu-fi__mobile-filter-toggle"},X={key:1,class:"facets-menu-fi__mobile-filter-toggle-wrapper"},j={key:2,class:"facets-menu-fi__filters"},J={key:0,class:"facets-menu-fi__clear-all-btn-wrapper"};function K(e,n,s,M,l,t){var b,C,p,S;const F=h("icon-fi"),y=h("clear-all-facets-fi"),A=h("select-fi"),T=h("button-fi"),H=h("facets-selection-fi");return s.facets?(i(),c("div",{key:0,class:r({"facets-menu-fi":!0,"facets-menu-fi--has-facets":t.displayedFacets.length,"facets-menu-fi--has-chips":(b=t.selectedElements)==null?void 0:b.length})},[e.isSM||l.showFacetsMobile||l.notMounted?(i(),c("div",{key:0,class:r({"facets-menu-fi__facets":!0,"facets-menu-fi__facets--leaving":l.leavingFacetsMobile,"facets-menu-fi__facets--show-result-btn":t.showMobileResultButton,"facets-menu-fi__facets--ssr":l.notMounted,[`facets-menu-fi__facets--cols-${s.columnsMax}`]:s.columnsMax})},[!e.isSM||l.notMounted?(i(),c("div",q,[f("div",{class:"facets-menu-fi__mobile-filter-back","data-test":"close-mobile-facets",onClick:n[0]||(n[0]=(...a)=>t.closeMobileFacets&&t.closeMobileFacets(...a))},[f("div",W,[u(F,{icon:"arrow-left"}),d(" "+g(e.$dict.get("facets.Show-Filters-Mobile")),1)])]),s.allowClearAll&&((C=t.selectedElements)!=null&&C.length)?(i(),w(y,{key:0,"data-test":"clear-all-facets",onClick:t.clearAllFacets},null,8,["onClick"])):o("",!0)])):o("",!0),f("div",{style:z(e.isSM?l.facetsStyle:{}),class:r({"facets-menu-fi__facets-wrapper":!0,"facets-menu-fi__facets-wrapper--transitioning":l.isClosing||l.isOpening})},[f("div",{ref:"selectedFacets",class:r({"facets-menu-fi__selected-facets":!0,"facets-menu-fi__selected-facets--fite":e.isFite,"facets-menu-fi__selected-facets--active":l.showFilters,"facets-menu-fi__selected-facets--centered":s.centered,"facets-menu-fi__selected-facets--ssr":l.notMounted})},[(i(!0),c(k,null,v(t.displayedFacets,(a,m)=>(i(),c("div",{key:a.name,class:r(["facets-menu-fi__selected-facet",m===0&&s.centered&&t.displayedFacets.length<t.maxFacetsInRow?`facets-menu-fi__selected-facet--start-${t.centeredSpace}`:null])},[E(e.$slots,"facets",{ref_for:!0,ref:"facets",facet:a,open:l.openFacet===a.name,toggleOpen:t.toggleOpen,change:t.change,close:t.close,idx:m,registerDomElement:t.registerDomElement},()=>[u(A,{ref_for:!0,ref:"facets",elements:a.elements,name:a.name,multiselect:a.multiselect,open:l.openFacet===a.name,large:"",onChange:t.change,onToggleOpen:_=>t.toggleOpen(a),onClose:_=>t.close(a)},null,8,["elements","name","multiselect","open","onChange","onToggleOpen","onClose"])],!0)],2))),128))],2)],6),t.showMobileResultButton&&!l.notMounted?(i(),w(T,{key:1,type:"button",class:"facets-menu-fi__show-results-mobile button-fi__primary--large","data-test":"show-results",onClick:t.closeMobileFacets},{default:B(()=>[d(g(e.$dict.get("search.Show-Results")),1)]),_:1},8,["onClick"])):o("",!0)],2)):o("",!0),(!e.isSM||l.notMounted)&&((p=t.displayedFacets)!=null&&p.length)?(i(),c("div",X,[f("div",{class:"facets-menu-fi__mobile-filter-toggle","data-test":"open-mobile-facets",onClick:n[1]||(n[1]=(...a)=>t.openMobileFacets&&t.openMobileFacets(...a))},[d(g(e.$dict.get("facets.Show-Filters-Mobile"))+" ",1),u(F,{icon:"filter"})])])):o("",!0),t.nonHiddenFacets.length>t.compactedFacets.length?(i(),c("div",j,[e.isSM||l.notMounted?(i(),c("div",{key:0,class:"facets-menu-fi__filters-headline","data-test":"toggle-facets",onClick:n[2]||(n[2]=(...a)=>t.toggleFacets&&t.toggleFacets(...a))},[d(g(l.showFilters?e.$dict.get("facets.Hide-All-Filters"):e.$dict.get("facets.Show-All-Filters"))+" ",1),f("span",{class:r({"facets-menu-fi__chevron":!0,"facets-menu-fi__chevron--active":l.showFilters&&!l.isClosing})},[u(F,{icon:"chevron-down"})],2)])):o("",!0)])):o("",!0),(S=t.selectedElements)!=null&&S.length?(i(),c("div",{key:3,class:r({"facets-menu-fi__selected-facets facets-menu-fi__chips":!0,"facets-menu-fi__selected-facets facets-menu-fi__chips--centered":s.chipsCentered})},[(i(!0),c(k,null,v(t.selectedElements,a=>(i(),w(H,{key:`${a.facet.name} ${a.element.name}`,element:a.element,facet:a.facet,onChange:t.change},V({_:2},[e.$slots.selection?{name:"display",fn:B(({facet:m,element:_})=>[E(e.$slots,"selection",{facet:m,element:_},void 0,!0)]),key:"0"}:void 0]),1032,["element","facet","onChange"]))),128)),s.allowClearAll&&t.selectedElements.length&&e.isSM&&s.showClearAll?(i(),c("div",J,[u(y,{"data-test":"clear-all-facets",onClick:t.clearAllFacets},null,8,["onClick"])])):o("",!0)],2)):o("",!0)],2)):o("",!0)}const Y=N(P,[["render",K],["__scopeId","data-v-f1d9794b"]]);export{Y as F};