"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.transArrayToPage = exports.paginateArray = void 0;
var transArrayToPage = exports.transArrayToPage = function transArrayToPage() {
  var array = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
  var size = arguments.length > 1 ? arguments[1] : undefined;
  var current = arguments.length > 2 ? arguments[2] : undefined;
  var offset = (current - 1) * size;
  var _paginateArray = paginateArray(array, size),
    total = _paginateArray.total,
    pages = _paginateArray.pages,
    allPageRecords = _paginateArray.allPageRecords;
  //
  // if (current > pages) {
  //   current = pages
  // }
  return {
    allPageRecords: allPageRecords,
    records: offset + size >= array.length ? array.slice(offset, array.length) : array.slice(offset, offset + size),
    total: total,
    pages: pages,
    // 总页数
    size: size,
    // 每页数量
    current: current,
    // 当前页码
    allRecord: array
  };
};
var paginateArray = exports.paginateArray = function paginateArray() {
  var array = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
  var size = arguments.length > 1 ? arguments[1] : undefined;
  var total = array.length;
  if (!array.length || Number(size) <= 0) {
    return {
      total: total,
      pages: 0,
      size: Number(size),
      allPageRecords: []
    };
  }
  var pages = array.length > 0 ? Math.ceil(array.length / Number(size)) : 0; // 页数
  var perLIST = [];
  for (var i = 0; i < pages; i++) {
    // console.log('循环' + pages + '次吗', i)
    var current = i + 1;
    var offset = (current - 1) * Number(size);
    // console.log('当前页', (offset + Number(size) >= array.length) ? array.slice(offset, array.length) : array.slice(offset, offset +  Number(size)))
    perLIST.push([offset + Number(size) >= array.length ? array.slice(offset, array.length) : array.slice(offset, offset + Number(size))]);
  }
  return {
    total: total,
    // 总数
    pages: pages,
    // 页数
    size: Number(size),
    allPageRecords: perLIST // 每页
  };
};