function Paginate(a){"use strict";function c(a){var c=new XMLHttpRequest,e=d();c.open("GET",b.source+e,!0),c.onload=function(){if(c.status>=200&&c.status<400){var d=JSON.parse(c.responseText);b.total=d[b.fields.Total],a(d[b.fields.Data])}else console.log(c.status)},c.onerror=function(a){console.log(a)},c.send()}function d(){var a="?page="+b.page+"&itensPerPage="+b.pageSize;if(b.params)for(var c in b.params)b.params.hasOwnProperty(c)&&(a+="&"+c+"="+b.params[c]);return a}function e(){return Math.round(b.total/b.pageSize)}function f(a){b.page0&&(b.page--,Paginate.prototype.render())}function h(a){b.page=0,Paginate.prototype.render()}function i(a){b.page=e(),Paginate.prototype.render()}function j(a,b){var c={};for(var d in b)b.hasOwnProperty(d)&&a[d]?c[d]=a[d]:c[d]=b[d];return c}const b=j(a,{source:null,params:null,container:null,page:0,pageSize:10,total:null,callback:null,fields:{Total:"Total",Data:"Items"},template:'
'});Paginate.prototype.render=function(){c(function(a){var c=b.template.replace("{{page}}",b.page).replace("{{maxPages}}",e()),d=document.querySelectorAll(b.container);return b.container?(d.length>0&&(d[0].innerHTML=c,document.querySelector(b.container+" #goToFirstPage").onclick=h,document.querySelector(b.container+" #goToNextPage").onclick=f,document.querySelector(b.container+" #goToLastPage").onclick=i,document.querySelector(b.container+" #goToPreviousPage").onclick=g),void(b.callback&&b.callback(a))):void console.log("indicate a container element")})}}