{"size": 3097, "ext": "js", "max_stars_repo_path": "compiled/Pagination.js", "max_stars_repo_name": "powerumc/vue-pagination-2-patch", "max_stars_repo_stars_event_min_datetime": "2021-02-09T08:51:25.000Z", "max_stars_repo_stars_event_max_datetime": "2021-02-09T08:51:25.000Z", "max_issues_repo_path": "node_modules/vue-pagination-2/compiled/Pagination.js", "max_issues_repo_name": "xuebapu/Work-showData", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "node_modules/vue-pagination-2/compiled/Pagination.js", "max_forks_repo_name": "xuebapu/Work-showData", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 1, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 28.9439252336, "max_line_length": 124, "alphanum_fraction": 0.6025185664}
'use strict';

var template = require('./template.js');

module.exports = {
  render: template(),
  props: {
    for: {
      type: String,
      required: true
    },
    records: {
      type: Number,
      required: true
    },
    perPage: {
      type: Number,
      required: false,
      default: 25
    },
    chunk: {
      type: Number,
      required: false,
      default: 10
    },
    countText: {
      type: String,
      required: false,
      default: 'Showing {from} to {to} of {count} records|{count} records|One record'
    }
  },
  computed: {
    pages: function pages() {
      if (!this.records) return [];

      return range(this.paginationStart, this.pagesInCurrentChunk);
    },
    totalPages: function totalPages() {
      return this.records ? Math.ceil(this.records / this.perPage) : 1;
    },
    totalChunks: function totalChunks() {
      return Math.ceil(this.totalPages / this.chunk);
    },
    currentChunk: function currentChunk() {
      return Math.ceil(this.page / this.chunk);
    },
    paginationStart: function paginationStart() {
      return (this.currentChunk - 1) * this.chunk + 1;
    },
    pagesInCurrentChunk: function pagesInCurrentChunk() {

      return this.paginationStart + this.chunk <= this.totalPages ? this.chunk : this.totalPages - this.paginationStart + 1;
    },
    count: function count() {

      var from = (this.page - 1) * this.perPage + 1;
      var to = this.page == this.totalPages ? this.records : from + this.perPage - 1;
      var parts = this.countText.split('|');
      var i = Math.min(this.records == 1 ? 2 : this.totalPages == 1 ? 1 : 0, parts.length - 1);

      return parts[i].replace('{count}', this.records).replace('{from}', from).replace('{to}', to);
    }
  },
  methods: {
    setPage: function setPage(page) {
      if (this.allowedPage(page)) {
        this.paginate(page);
      }
    },
    next: function next() {
      return this.setPage(this.page + 1);
    },
    prev: function prev() {
      return this.setPage(this.page - 1);
    },
    nextChunk: function nextChunk() {
      return this.setChunk(1);
    },
    prevChunk: function prevChunk() {
      return this.setChunk(-1);
    },
    setChunk: function setChunk(direction) {
      this.setPage((this.currentChunk - 1 + direction) * this.chunk + 1);
    },
    allowedPage: function allowedPage(page) {
      return page >= 1 && page <= this.totalPages;
    },
    allowedChunk: function allowedChunk(direction) {
      return direction == 1 && this.currentChunk < this.totalChunks || direction == -1 && this.currentChunk > 1;
    },
    allowedPageClass: function allowedPageClass(direction) {
      return this.allowedPage(direction) ? '' : 'disabled';
    },
    allowedChunkClass: function allowedChunkClass(direction) {
      return this.allowedChunk(direction) ? '' : 'disabled';
    },
    activeClass: function activeClass(page) {
      return this.page == page ? 'active' : '';
    }
  }
};

function range(start, count) {
  return Array.apply(0, Array(count)).map(function (element, index) {
    return index + start;
  });
}