import{q as ee,i as L,a as p,b as S,W as te,o as le,w as se,D as n,y as a,z as y,U as A,A as j,H as F,J as M,K as C,I as u,C as G,P as z,R as re,Q as ne,a5 as ae}from"./EchoChannel-Bg1-kez_.js";import{s as oe}from"./Search-CK7cDv2i.js";import{_ as D}from"./FilterValue.vue_vue_type_script_setup_true_lang-CylUfQaY.js";import{d as ie,r as O,o as I}from"./search-VYKRAp0q.js";import{_ as ue}from"./_plugin-vue_export-helper-DlAUqK2U.js";import"./Tick-DwQKjUFm.js";const ce=`<svg width="13" height="8" viewBox="0 0 13 8" fill="none" xmlns="http://www.w3.org/2000/svg"> <path d="M7.04827 6.80468L12.4375 1.07882L11.7771 0.429688L6.5 5.22471L1.22291 0.429688L0.5625 1.07882L5.95173 6.80468L6.5 7.39258L7.04827 6.80468Z" fill="#645AFF"/> </svg> `,de={class:"group-hover:underline"},pe=["innerHTML"],fe={key:0,class:"w-full text-left text-qorus-grey-mid truncate text-ellipsis capitalize"},ve={key:0,class:"pb-4"},me=["innerHTML"],ye={key:1,class:"w-full"},k=2,w=10,he=ee({__name:"FilterValues",props:{displayedFilter:{}},setup(K){const i=K,h=L("debounce");L("throttle");const N=L("searchForFacetValues"),o=p([]),c=p(k),f=p(w),P=()=>{const e=c.value+5;c.value=e<o.value.length?e:o.value.length,f.value=null},R=S(()=>{const e=o.value.length,t=e>k&&c.value!==e,l=e===1&&g()>=w&&f;return(t||l)&&!i.displayedFilter.fetchFromAlgolia}),J=()=>{c.value=2,f.value=10},Q=S(()=>{const e=o.value.length,t=e>k&&c.value===e,l=e===1&&g()>=w&&!f;return(t||l)&&!i.displayedFilter.fetchFromAlgolia});te(()=>{q()}),le(()=>{x()});const q=()=>{var e;(e=i.displayedFilter)!=null&&e.fetchFromAlgolia?(o.value=[{items:ie.value[i.displayedFilter.key]??[]}],V()):(o.value=i.displayedFilter.data,V())},$=p(null),v=()=>{var e;return I.value===((e=i.displayedFilter)==null?void 0:e.key)},U=h(()=>{if(v()){const e=document.querySelector("#scrollable__filters"),t=$.value;e&&t&&(e.scrollTop=0-t.offsetTop)}},.25),x=h(()=>{const e=document.querySelector(".search__filter__element");e==null||e.focus(),U()},.25),W=e=>{I.value=v()?"all":e.key,x(),c.value=k,f.value=w},T=p(!1),V=()=>{T.value=g()>=10||i.displayedFilter.fetchFromAlgolia},g=()=>{let e=0;return o.value.forEach(t=>{let l=t.items;Array.isArray(t.items)||(l=Object.keys(t.items));const r=l==null?void 0:l.length;r&&(e+=r)}),e},_=S(()=>{var e,t;return(t=(e=O[i.displayedFilter.key])==null?void 0:e.sort())==null?void 0:t.filter(l=>{var r;return!((r=i.displayedFilter.data)!=null&&r.map(m=>m.title).includes(l))})}),d=p(""),b=p(null);se(d,async e=>{var t;return e===""?q():(t=i.displayedFilter)!=null&&t.fetchFromAlgolia?Z(e):(b.value||(b.value=o.value.reduce((l,r)=>(Array.isArray(r.items)||(r.items=Object.values(r.items)),[...l,...r.items]),[])),X(e))});const Z=h(async e=>{if(!d.value)return;const t=await N("posts_sorted_date_desc",I.value,e,100);o.value=[{items:t??[]}]},250),X=h(e=>{if(!d.value)return;const t=e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),l=/[!"#$%&'()*+,-./:;<=>?@[\]^_`{|}~]/g,r=new RegExp(t.replace(l,""),"i"),m=b.value.filter(s=>r.test(s.replace(l,"")))??[];o.value=[{items:m??[]}]},250),Y=(e,t)=>{var l;return(l=t==null?void 0:t.value)!=null&&l.length?{value:t.value}:typeof e=="string"?{value:e}:typeof t=="string"?{value:t}:t};return(e,t)=>{var l,r,m;return n(),a("div",{ref_key:"filter__element",ref:$,class:"border-b-2 border-qorus-purple"},[y("button",{class:j(["group w-full h-full bg-white z-20 px-8 py-6 text-lg flex flex-wrap justify-between items-center",{underline:v()}]),onClick:t[0]||(t[0]=G(s=>W(e.displayedFilter),["prevent"]))},[y("span",de,A(e.displayedFilter.title)+" "+A(((l=_.value)==null?void 0:l.length)>0?`(${(r=_.value)==null?void 0:r.length})`:""),1),y("span",{class:j({"rotate-180":v()}),innerHTML:F(ce)},null,10,pe),!v()&&((m=F(O)[e.displayedFilter.key])==null?void 0:m.length)>0?(n(),a("span",fe,[(n(!0),a(M,null,C(_.value,s=>(n(),a("span",null,A(s.replace("_"," "))+"; ",1))),256))])):u("",!0)],2),z(ae,{name:"slide"},{default:re(()=>[v()?(n(),a("div",ve,[T.value?(n(),a("form",{key:0,onSubmit:G(()=>null,["prevent"]),class:"my-4 mx-8 flex border-qorus-grey-light border-b-[1px]"},[y("span",{class:"flex justify-center items-center",innerHTML:F(oe)},null,8,me),y("input",{type:"text",placeholder:"Search filter",onInput:t[1]||(t[1]=s=>d.value=s.target.value),class:"search__filter__element indent-2 font-light w-full"},null,32)],32)):u("",!0),(n(!0),a(M,null,C(o.value.slice(0,c.value),s=>{var B;return n(),a("div",null,[s.title&&d.value===""?(n(),ne(D,{key:0,"filter-key":e.displayedFilter.key,"group-title":s.title,index:null,item:null},null,8,["filter-key","group-title"])):u("",!0),y("ul",null,[(n(!0),a(M,null,C(Array.isArray(s.items)?(B=s.items)==null?void 0:B.slice(0,f.value??s.items.length):s.items,(E,H)=>(n(),a("li",{key:H,class:"w-full h-full"},[z(D,{"filter-key":e.displayedFilter.key,"group-title":s.title??e.displayedFilter.title,item:E,index:Y(H,E)},null,8,["filter-key","group-title","item","index"])]))),128))])])}),256)),!d.value||d.value===""?(n(),a("div",ye,[R.value?(n(),a("button",{key:0,class:"w-full text-qorus-purple underline text-xs px-8 text-right hover:opacity-75",onClick:t[2]||(t[2]=s=>P())},"Show more")):u("",!0),Q.value?(n(),a("button",{key:1,class:"w-full text-qorus-purple underline text-xs px-8 text-right hover:opacity-75",onClick:t[3]||(t[3]=s=>J())},"Show less")):u("",!0),g()>=10&&e.displayedFilter.fetchFromAlgolia?(n(),a("button",{key:2,class:"w-full text-qorus-purple underline text-xs px-8 text-right hover:opacity-75",onClick:t[4]||(t[4]=s=>F(x)())},"Search for more")):u("",!0)])):u("",!0)])):u("",!0)]),_:1})],512)}}}),be=ue(he,[["__scopeId","data-v-8211054f"]]);export{be as default};