import getListLength from "./getListLength";

// Check list if there are more items to load
function hasMoreItems(_ref) {
  var list = _ref.list,
    currentPage = _ref.currentPage,
    currentList = _ref.currentList,
    pagination = _ref.pagination;
  var totalPages = (currentList === null || currentList === void 0 ? void 0 : currentList.totalPages) || (pagination === null || pagination === void 0 ? void 0 : pagination.totalPages);
  var totalItems = (currentList === null || currentList === void 0 ? void 0 : currentList.totalItems) || (pagination === null || pagination === void 0 ? void 0 : pagination.totalItems);
  var rows = (currentList === null || currentList === void 0 ? void 0 : currentList.rows) || (pagination === null || pagination === void 0 ? void 0 : pagination.rows);
  // 根据单页条数和总条数获取总页数
  if (!totalPages && totalItems && rows) {
    totalPages = Math.ceil(totalItems / rows);
  }

  // 当前页数大于等于总页数, 无下一页
  if (typeof totalPages === 'number' && currentPage >= totalPages) {
    return false;
  }
  // 列表数大于总条数, 无下一页
  if (typeof totalItems === 'number' && getListLength(list) >= totalItems) {
    return false;
  }
  // 当前页列表数小于页限制条数, 无下一页
  if (typeof rows === 'number' && getListLength(currentList) < rows) {
    return false;
  }
  return true;
}
export default hasMoreItems;