import{K as d,m as h,A as y,j as u,k as a,v as n,C as g,F as p,B as P,t as B,X as r}from"./BCLrUOBx.js";const m={name:"Pagination",data(){return{sortByType:(this._.provides[r]||this.$route).query.orderByType||"desc",sortBy:(this._.provides[r]||this.$route).query.orderBy||"created_at",currentPage:Number((this._.provides[r]||this.$route).query.page)||this.page,search:(this._.provides[r]||this.$route).query.q||null}},props:{changingRoute:{type:Boolean,default:!0},page:{type:Number,default:1},totalPage:{type:Number},pagePer:{type:Number,default:5}},watch:{},directives:{},components:{},mixins:[],computed:{getActivePages(){let e=this.getPage+(this.pagePer-1);e%this.pagePer!==0&&(e=parseInt(e/this.pagePer)*this.pagePer);const t=e-(this.pagePer-1);return e>=this.totalPage&&(e=this.totalPage),[t-1,e]},getPage(){return this.currentPage},allPages(){const e=[];for(let t=1;t<=this.totalPage;t++)e.push(t);return e}},methods:{routeParam(){this.isDefaultPage()?this.resettingRoute():(this.clearQuery(),this.$emit("fetching-data")),this.scrollToTop()},resettingRoute(e={}){this.clearQuery(),this.$router.push({query:{...e,orderBy:this.orderBy,orderByType:this.orderByType,page:this.currentPage,q:this.search}}),this.$emit("fetching-data")},clearQuery(){this.orderByType="desc",this.orderBy="created_at",this.currentPage=1},isDefaultPage(){return this.orderByType==="desc"&&this.orderBy==="created_at"&&this.currentPage===1},settingRoute(){this.$router.push({query:{...(this._.provides[r]||this.$route).query,orderBy:this.orderBy,orderByType:this.orderByType,page:this.currentPage,q:this.search}})},dropdownSelected(e,t){this.currentPage=1,e?this.orderByType=t.key:this.orderBy=t.key,this.getDataWithRoute()},scrollToTop(){window.scrollTo(0,0)},getDataFromRoute(){this.sortByType=(this._.provides[r]||this.$route).query.orderByType||"desc",this.sortBy=(this._.provides[r]||this.$route).query.orderBy||"created_at",this.currentPage=Number((this._.provides[r]||this.$route).query.page)||1,this.search=(this._.provides[r]||this.$route).query.q||null,this.$emit("fetching-data")},getDataWithRoute(){this.changingRoute&&(this.settingRoute(),this.scrollToTop()),this.$emit("fetching-data",{orderBy:this.orderBy,orderByType:this.orderByType,page:this.currentPage,q:this.q})},navigate(e){e>0&&this.currentPage>=this.totalPage||e<0&&this.currentPage<=1||(this.currentPage+=e,this.getDataWithRoute())},paginate(e){this.currentPage!==e&&(this.currentPage=e,this.getDataWithRoute())},loadData(){this.getDataFromRoute()}},unmounted(){},mounted(){}},f={key:0,class:"pagination"},v=["onClick"];function _(e,t,l,T,o,s){return l.totalPage>1?(u(),h("ul",f,[a("li",{class:g({disabled:o.currentPage===1}),onClick:t[0]||(t[0]=n(i=>s.navigate(-1),["prevent"]))},t[2]||(t[2]=[a("i",{class:"icon arrow-left black"},null,-1)]),2),(u(!0),h(p,null,P(s.allPages.slice(s.getActivePages[0],s.getActivePages[1]),(i,c)=>(u(),h("li",{class:g(["page",{disabled:o.currentPage===i}]),key:c,onClick:n(q=>s.paginate(i),["prevent"])},[a("span",null,B(i),1)],10,v))),128)),a("li",{class:g({disabled:o.currentPage===l.totalPage}),onClick:t[1]||(t[1]=n(i=>s.navigate(1),["prevent"]))},t[3]||(t[3]=[a("i",{class:"icon arrow-right black"},null,-1)]),2)])):y("",!0)}const R=d(m,[["render",_]]);export{R as default};
