import{i as q,a as p,o as P,b as _,D as f,y,S as L,Q as U,I as m,H as B}from"./EchoChannel-Bg1-kez_.js";import E from"./SpinnerLoader-WkHXMWXk.js";import{f as M,r as o}from"./search-VYKRAp0q.js";const N=["disabled"],R=500,V={__name:"LoadMore",props:{resultLoading:{type:Boolean,required:!0},filterGroupTitles:{required:!0},nextPageUrl:{type:[String,URL],required:!0}},emits:["more"],setup(n,{emit:h}){const l=n,g=h,b=q("debounce"),a=p(!1),s=p(null);P(()=>{u(l.nextPageUrl)});const v=_(()=>{var r,e,t;return((t=(e=(r=s.value)==null?void 0:r.posts)==null?void 0:e.data)==null?void 0:t.length)>0}),u=async r=>{if(!r)return s.value=null;try{const e=x(r),t=await fetch(e.toString(),{headers:{"X-Requested-With":"XMLHttpRequest"}});s.value=await t.json()}catch(e){return console.error(e),a.value=!1}},x=r=>{const e=new URL(r);return M.forEach(t=>{var i;((i=o[t])==null?void 0:i.length)>0&&(e.searchParams.delete(t),o[t].forEach(c=>{var d;(d=l.filterGroupTitles.value)!=null&&d.includes(c)||e.searchParams.append(t+"[]",c)}))}),o.winner&&e.searchParams.append("winner","1"),o.default_searchable_models.forEach(t=>{e.searchParams.append("default_searchable_models[]",t)}),e},w=b(()=>{var r,e;try{g("more",s.value),u((e=(r=s.value)==null?void 0:r.posts)==null?void 0:e.next_page_url),a.value=!1}catch(t){return console.error(t),a.value=!1}},R);return(r,e)=>v.value?(f(),y("button",{key:0,onClick:e[0]||(e[0]=t=>{a.value=!0,B(w)()}),class:"w-fit flex gap-x-4 items-center border-qorus-purple border-2 text-qorus-purple p-2 cursor-pointer hover:bg-qorus-purple hover:text-white disabled:cursor-not-allowed disabled:bg-qorus-purple disabled:text-white",disabled:n.resultLoading||a.value},[e[1]||(e[1]=L(" View more ")),n.resultLoading||a.value?(f(),U(E,{key:0})):m("",!0)],8,N)):m("",!0)}};export{V as default};