import{_ as c,$ as r,c as o,e as y,b as a,E as n,D as g,F as p,g as P,o as h,t as m}from"./Bgmy51Qv.js";const R={data(){return{listParams:{type:"desc",orderby:"created_at",page:1,q:null}}},methods:{settingRouteParam(){this.listParams={...this.listParams,type:this.$route.query.orderbyType||"desc",orderby:this.$route.query.orderby||"created_at",page:Number(this.$route.query.page)||1,q:this.$route.query.q||null}}}},B={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()}},destroyed(){window.removeEventListener("popstate",this.loadData)},mounted(){window.addEventListener("popstate",this.loadData)}},f={class:"dply-felx j-right"},q={key:0,class:"pagination"},v=["onClick"];function _(e,t,d,T,u,s){return h(),o("div",f,[d.totalPage>1?(h(),o("ul",q,[a("li",{class:g({disabled:u.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),(h(!0),o(p,null,P(s.allPages.slice(s.getActivePages[0],s.getActivePages[1]),(i,l)=>(h(),o("li",{class:g(["page",{disabled:u.currentPage===i}]),key:l,onClick:n(b=>s.paginate(i),["prevent"])},[a("span",null,m(i),1)],10,v))),128)),a("li",{class:g({disabled:u.currentPage===d.totalPage}),onClick:t[1]||(t[1]=n(i=>s.navigate(1),["prevent"]))},t[3]||(t[3]=[a("i",{class:"icon arrow-right black"}," ",-1)]),2)])):y("",!0)])}const D=c(B,[["render",_]]);export{D as P,R as r};
