import{u as h,w as f}from"./chunk-COFYR5MX.js";import{Ec as P,_ as b,a as u,b as o,ca as p,ta as d}from"./chunk-2MUIW2M6.js";var l=class m{constructor(r,e){this.router=r;this.route=e}calculatePaginationState(r){let{currentPage:e,pageSize:a,totalItems:n}=r,t=Math.ceil(n/a)||1,i=Math.max(1,Math.min(e,t)),g=(i-1)*a+1,s=Math.min(i*a,n),c=i>1,v=ic+1);let n=[],t=Math.floor(a/2);n.push(1);let i=Math.max(2,r-t),g=Math.min(e-1,r+t);r<=t+1?g=Math.min(e-1,a-1):r>=e-t&&(i=Math.max(2,e-a+2)),i>2&&n.push("...");for(let s=i;s<=g;s++)n.push(s);return g1&&n.push(e),n}updateUrlQueryParams(r,e,a=!0){let n=a?u({},this.route.snapshot.queryParams):{};n.page=r,e&&(n.pageSize=e),this.router.navigate([],{relativeTo:this.route,queryParams:n,queryParamsHandling:a?"merge":"replace"})}getPaginationFromUrl(r=10){let e=this.route.snapshot.queryParams,a=parseInt(e.page)||1,n=parseInt(e.pageSize)||r;return{page:Math.max(1,a),pageSize:Math.max(1,n)}}createPaginationManager(r){let e=d(r),a=P(()=>this.calculatePaginationState(e())),n=P(()=>this.calculatePageNumbers(a().currentPage,a().totalPages,5));return{config:e,state:a,pageNumbers:n,setPage:t=>{e.update(i=>o(u({},i),{currentPage:t}))},setPageSize:t=>{e.update(i=>o(u({},i),{pageSize:t,currentPage:1}))},setTotalItems:t=>{e.update(i=>o(u({},i),{totalItems:t}))},nextPage:()=>{a().hasNextPage&&e.update(t=>o(u({},t),{currentPage:t.currentPage+1}))},prevPage:()=>{a().hasPreviousPage&&e.update(t=>o(u({},t),{currentPage:t.currentPage-1}))},firstPage:()=>{e.update(t=>o(u({},t),{currentPage:1}))},lastPage:()=>{e.update(t=>o(u({},t),{currentPage:a().totalPages}))}}}getPaginatedItems(r,e,a){let n=(e-1)*a,t=n+a;return r.slice(n,t)}static \u0275fac=function(e){return new(e||m)(p(f),p(h))};static \u0275prov=b({token:m,factory:m.\u0275fac,providedIn:"root"})};export{l as a};