"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),t=require("primereact/utils"),n=require("primereact/ripple"),r=require("primereact/dropdown"),o=require("primereact/inputnumber");function a(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var s=a(e);function i(e){if(Array.isArray(e))return e}function l(e,t){var n=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=n){var r,o,a=[],s=!0,i=!1;try{for(n=n.call(e);!(s=(r=n.next()).done)&&(a.push(r.value),!t||a.length!==t);s=!0);}catch(e){i=!0,o=e}finally{try{s||null==n.return||n.return()}finally{if(i)throw o}}return a}}function p(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n0}},{key:"render",value:function(){var e=this.hasOptions(),n=e?this.props.options.map((function(e){return{label:String(e),value:e}})):[],o=e?s.default.createElement(r.Dropdown,{value:this.props.value,options:n,onChange:this.props.onChange,appendTo:this.props.appendTo,disabled:this.props.disabled}):null;return this.props.template?t.ObjectUtils.getJSXElement(this.props.template,{value:this.props.value,options:n,onChange:this.props.onChange,appendTo:this.props.appendTo,currentPage:this.props.page,totalPages:this.props.pageCount,totalRecords:this.props.totalRecords,disabled:this.props.disabled,element:o,props:this.props}):o}}]),l}();function D(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function M(e){for(var t=1;t0?this.props.page+1:0,n=s.default.createElement(o.InputNumber,{value:e,onChange:this.onChange,className:"p-paginator-page-input",disabled:this.props.disabled});return this.props.template?t.ObjectUtils.getJSXElement(this.props.template,{value:e,onChange:this.onChange,disabled:this.props.disabled,className:"p-paginator-page-input",element:n,props:this.props}):n}}]),l}();function _(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}k(X,"defaultProps",{page:null,rows:null,pageCount:null,disabled:!1,template:null,onChange:null});var A=function(n){v(p,e.Component);var r,o,a=(r=p,o=_(),function(){var e,t=b(r);if(o){var n=b(this).constructor;e=Reflect.construct(t,arguments,n)}else e=t.apply(this,arguments);return P(this,e)});function p(e){var t;return h(this,p),(t=a.call(this,e)).changePageToFirst=t.changePageToFirst.bind(m(t)),t.changePageToPrev=t.changePageToPrev.bind(m(t)),t.changePageToNext=t.changePageToNext.bind(m(t)),t.changePageToLast=t.changePageToLast.bind(m(t)),t.onRowsChange=t.onRowsChange.bind(m(t)),t.changePage=t.changePage.bind(m(t)),t.onPageLinkClick=t.onPageLinkClick.bind(m(t)),t}return d(p,[{key:"isFirstPage",value:function(){return 0===this.getPage()}},{key:"isLastPage",value:function(){return this.getPage()===this.getPageCount()-1}},{key:"getPageCount",value:function(){return Math.ceil(this.props.totalRecords/this.props.rows)}},{key:"calculatePageLinkBoundaries",value:function(){var e=this.getPageCount(),t=Math.min(this.props.pageLinkSize,e),n=Math.max(0,Math.ceil(this.getPage()-t/2)),r=Math.min(e-1,n+t-1);return[n=Math.max(0,n-(this.props.pageLinkSize-(r-n+1))),r]}},{key:"updatePageLinks",value:function(){for(var e=[],t=this.calculatePageLinkBoundaries(),n=t[1],r=t[0];r<=n;r++)e.push(r+1);return e}},{key:"changePage",value:function(e,t){var n=this.getPageCount(),r=Math.floor(e/t);r>=0&&r0&&e.totalRecords!==this.props.totalRecords&&this.props.first>=this.props.totalRecords&&this.changePage((this.getPageCount()-1)*this.props.rows,this.props.rows):this.changePage(0,this.props.rows),this.isRowChanged=!1}},{key:"renderElement",value:function(e,t){var n;switch(e){case"FirstPageLink":n=s.default.createElement(w,{key:e,onClick:this.changePageToFirst,disabled:this.isFirstPage()||this.empty(),template:t});break;case"PrevPageLink":n=s.default.createElement(N,{key:e,onClick:this.changePageToPrev,disabled:this.isFirstPage()||this.empty(),template:t});break;case"NextPageLink":n=s.default.createElement(O,{key:e,onClick:this.changePageToNext,disabled:this.isLastPage()||this.empty(),template:t});break;case"LastPageLink":n=s.default.createElement(T,{key:e,onClick:this.changePageToLast,disabled:this.isLastPage()||this.empty(),template:t});break;case"PageLinks":n=s.default.createElement(S,{key:e,value:this.updatePageLinks(),page:this.getPage(),rows:this.props.rows,pageCount:this.getPageCount(),onClick:this.onPageLinkClick,template:t});break;case"RowsPerPageDropdown":n=s.default.createElement(B,{key:e,value:this.props.rows,page:this.getPage(),pageCount:this.getPageCount(),totalRecords:this.props.totalRecords,options:this.props.rowsPerPageOptions,onChange:this.onRowsChange,appendTo:this.props.dropdownAppendTo,template:t,disabled:this.empty()});break;case"CurrentPageReport":n=s.default.createElement(J,{reportTemplate:this.props.currentPageReportTemplate,key:e,page:this.getPage(),pageCount:this.getPageCount(),first:this.props.first,rows:this.props.rows,totalRecords:this.props.totalRecords,template:t});break;case"JumpToPageInput":n=s.default.createElement(X,{key:e,rows:this.props.rows,page:this.getPage(),pageCount:this.getPageCount(),onChange:this.changePage,disabled:this.empty(),template:t});break;default:n=null}return n}},{key:"renderElements",value:function(){var e=this,t=this.props.template;return t?"object"===f(t)?t.layout?t.layout.split(" ").map((function(n){var r=n.trim();return e.renderElement(r,t[r])})):Object.entries(t).map((function(t){var n,r,o=(r=2,i(n=t)||l(n,r)||u(n,r)||c());return e.renderElement(o[0],o[1])})):t.split(" ").map((function(t){return e.renderElement(t.trim())})):null}},{key:"render",value:function(){if(this.props.alwaysShow||1!==this.getPageCount()){var e=t.classNames("p-paginator p-component",this.props.className),n=t.ObjectUtils.getJSXElement(this.props.leftContent,this.props),r=t.ObjectUtils.getJSXElement(this.props.rightContent,this.props),o=this.renderElements();return s.default.createElement("div",{className:e,style:this.props.style},n&&s.default.createElement("div",{className:"p-paginator-left-content"},n),o,r&&s.default.createElement("div",{className:"p-paginator-right-content"},r))}return null}}]),p}();k(A,"defaultProps",{totalRecords:0,rows:0,first:0,pageLinkSize:5,rowsPerPageOptions:null,alwaysShow:!0,style:null,className:null,template:"FirstPageLink PrevPageLink PageLinks NextPageLink LastPageLink RowsPerPageDropdown",onPageChange:null,leftContent:null,rightContent:null,dropdownAppendTo:null,currentPageReportTemplate:"({currentPage} of {totalPages})"}),exports.Paginator=A;