import{b as x}from"./chunk-UZHOGHQD.js";import{C as E,H as I}from"./chunk-GRQQH4TI.js";import{a as C}from"./chunk-YXNSGUXN.js";import{A as y,E as F,H as P}from"./chunk-2YE7XEKS.js";import{H as r,I as $,O as d,P as g,R as m,T as f,Y as p,_ as o,da as u,k as n,ka as S,l,pa as s,ub as b,vd as v,w as t,x as c}from"./chunk-UNHECMG2.js";var R="page",O=(()=>{class a{constructor(e){this.location=s(v),this.loadingService=s(C),this.settings=s(y),this.sortService=s(I),this.loading$=this.loadingService.loading$,this.loadingPage$=this.loadingService.loading(R),this.sortCriteria$=this.sortService.sortCriteria$,this.sortCriteria=this.sortService.sortCriteria,this.filter$=new l(this.getInitialFilter()),this.isFilterValid$=this.filter$.pipe(t(this.isValidFilter.bind(this))),this.validFilter$=this.filter$.pipe($(this.isValidFilter.bind(this)),f(P),o(1)),this.resetEntries$=new n,this.nextPage$=new n,this.page$=r(this.nextPage$.pipe(t(()=>"next")),r(this.resetEntries$,this.validFilter$,this.sortCriteria$).pipe(t(()=>"reset"))).pipe(p((i,h)=>h==="next"?i+1:0,0)),this.offset$=this.page$.pipe(t(i=>i*this.settings.paginationLimit)),this.pageResult$=c([this.validFilter$,this.sortCriteria$,this.offset$]).pipe(g(10),d(E(this.loadEntries.bind(this))),o(1)),this.entries$=r(r(this.resetEntries$,this.validFilter$,this.sortCriteria$).pipe(t(()=>({action:"reset"}))),this.pageResult$.pipe(t(i=>i.offset===0?{action:"reset",entries:i.entries}:{action:"append",entries:i.entries}))).pipe(p(this.entriesActionReducer.bind(this),[]),o(1)),this.total$=this.pageResult$.pipe(t(({total:i})=>i)),this.hasMore$=this.pageResult$.pipe(t(({offset:i,total:h})=>i<h-this.settings.paginationLimit)),this.queryParams$=this.filter$.pipe(t(this.buildParamsFromFilter.bind(this))),this.queryParamsString$=this.queryParams$.pipe(t(x)),this.destroy$=new n,this.queryParamsString$.pipe(u(this.destroy$)).subscribe(i=>this.location.replaceState(e,i)),this.sortService.sortCriteria.set(this.getInitialSortCriteria())}ngOnDestroy(){this.destroy$.next()}setFilter(e){this.filter$.next(F(e))}nextPage(){this.hasMore$.pipe(m(1)).subscribe(e=>{e&&this.nextPage$.next()})}resetEntries(){this.resetEntries$.next()}getInitialSortCriteria(){return null}entriesActionReducer(e,i){switch(i.action){case"append":return[...e,...i.entries];case"reset":return i.entries?i.entries:[];default:return e}}static{this.\u0275fac=function(i){b()}}static{this.\u0275prov=S({token:a,factory:a.\u0275fac})}}return a})();export{R as a,O as b};
