Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}}),require(`../../chunk-Bmb41Sf3.cjs`);const e=require(`../../_plugin-vue_export-helper-D8jCH6HB.cjs`),t=require(`../../localization/index.cjs`),n=require(`../button/button.cjs`);let r=require(`vue`),i=require(`@dialpad/dialtone-icons/vue3`);var a={compatConfig:{MODE:3},name:`DtPagination`,components:{DtButton:n.default,DtIconChevronLeft:i.DtIconChevronLeft,DtIconChevronRight:i.DtIconChevronRight,DtIconMoreHorizontal:i.DtIconMoreHorizontal},props:{ariaLabel:{type:String,required:!0},totalPages:{type:Number,required:!0},activePage:{type:Number,default:1},maxVisible:{type:Number,default:5},hideEdges:{type:Boolean,default:!1}},emits:[`change`],data(){return{currentPage:this.activePage,i18n:new t.DialtoneLocalization}},computed:{isFirstPage(){return this.currentPage===1},isLastPage(){return this.currentPage===this.totalPages},pages(){if(this.maxVisible===0)return[];if(this.totalPages<=this.maxVisible)return this.range(1,this.totalPages);let e=this.maxVisible-1,t=this.totalPages-e+1;if(this.hideEdges&&(e+=1,--t),this.currentPage<e){let t=[...this.range(1,e),`...`];return this.hideEdges||t.push(this.totalPages),t}if(this.currentPage>t){let e=[`...`,...this.range(t,this.totalPages)];return this.hideEdges||e.unshift(1),e}let n=this.maxVisible-(3-this.maxVisible%2),r=Math.floor(n/2),i=this.currentPage-r,a=this.currentPage+r;this.hideEdges&&(--i,a+=1);let o=[`...`,...this.range(i,a),`...`];return this.hideEdges?o:[1,...o,this.totalPages]},prevAriaLabel(){return this.isFirstPage?this.i18n.$t(`DIALTONE_PAGINATION_FIRST_PAGE`):this.i18n.$t(`DIALTONE_PAGINATION_PREVIOUS_PAGE`)},nextAriaLabel(){return this.isLastPage?this.i18n.$t(`DIALTONE_PAGINATION_LAST_PAGE`):this.i18n.$t(`DIALTONE_PAGINATION_NEXT_PAGE`)},pageNumberAriaLabel(){return e=>e===this.totalPages?`${this.i18n.$t(`DIALTONE_PAGINATION_LAST_PAGE`)} ${e}`:`${this.i18n.$t(`DIALTONE_PAGINATION_PAGE_NUMBER`,{page:e})}`}},watch:{activePage(){this.currentPage=this.activePage},totalPages(e){(this.currentPage>e||this.currentPage<=0)&&(this.currentPage=e)}},methods:{range(e,t){let n=[];e=e>0?e:1;for(let r=e;r<=t;r++)n.push(r);return n},changePage(e){this.currentPage=e,this.$emit(`change`,this.currentPage)}}},o=[`aria-label`],s={key:0,class:`d-pagination__separator-icon`,"data-qa":`dt-pagination-separator`};function c(e,t,n,i,a,c){let l=(0,r.resolveComponent)(`dt-icon-chevron-left`),u=(0,r.resolveComponent)(`dt-button`),d=(0,r.resolveComponent)(`dt-icon-more-horizontal`),f=(0,r.resolveComponent)(`dt-icon-chevron-right`);return(0,r.withDirectives)(((0,r.openBlock)(),(0,r.createElementBlock)(`nav`,{"aria-label":n.ariaLabel,class:`d-pagination`},[(0,r.createVNode)(u,{class:`d-pagination__button`,"data-qa":`dt-pagination-prev`,"aria-label":c.prevAriaLabel,kind:`muted`,importance:`clear`,disabled:c.isFirstPage,onClick:t[0]||(t[0]=e=>c.changePage(a.currentPage-1))},{icon:(0,r.withCtx)(()=>[(0,r.createVNode)(l,{size:`300`})]),_:1},8,[`aria-label`,`disabled`]),((0,r.openBlock)(!0),(0,r.createElementBlock)(r.Fragment,null,(0,r.renderList)(c.pages,(e,t)=>((0,r.openBlock)(),(0,r.createElementBlock)(`div`,{key:`page-${e}-${t}`,class:(0,r.normalizeClass)({"d-pagination__separator":isNaN(Number(e))})},[isNaN(Number(e))?((0,r.openBlock)(),(0,r.createElementBlock)(`div`,s,[(0,r.createVNode)(d,{size:`300`})])):((0,r.openBlock)(),(0,r.createBlock)(u,{key:1,"aria-label":c.pageNumberAriaLabel(e),kind:a.currentPage===e?`default`:`muted`,importance:a.currentPage===e?`primary`:`clear`,"label-class":``,onClick:t=>c.changePage(e)},{default:(0,r.withCtx)(()=>[(0,r.createTextVNode)((0,r.toDisplayString)(e),1)]),_:2},1032,[`aria-label`,`kind`,`importance`,`onClick`]))],2))),128)),(0,r.createVNode)(u,{class:`d-pagination__button`,"data-qa":`dt-pagination-next`,"aria-label":c.nextAriaLabel,disabled:c.isLastPage,kind:`muted`,importance:`clear`,onClick:t[1]||(t[1]=e=>c.changePage(a.currentPage+1))},{icon:(0,r.withCtx)(()=>[(0,r.createVNode)(f,{size:`300`})]),_:1},8,[`aria-label`,`disabled`])],8,o)),[[r.vShow,n.totalPages>0]])}var l=e.t(a,[[`render`,c]]);exports.default=l;
//# sourceMappingURL=pagination.cjs.map