const getNumberOfPages = (totalRows, rowsPerPage) => {
    return Math.ceil(totalRows / rowsPerPage);
};
const getPageRangeList = (currentPage, numTotalPages, limiter) => {
    const lastPage = _getLastPage(currentPage, numTotalPages, limiter);
    const firstPage = _getFirstPage(lastPage, limiter);
    const pageNumbers = _range(Math.min(limiter, numTotalPages), firstPage);
    if (!pageNumbers.includes(1)) {
        if (!pageNumbers.includes(2)) {
            pageNumbers.unshift(-1);
        }
        pageNumbers.unshift(1);
    }
    if (!pageNumbers.includes(numTotalPages)) {
        if (!pageNumbers.includes(numTotalPages - 1)) {
            pageNumbers.push(-1);
        }
        pageNumbers.push(numTotalPages);
    }
    return pageNumbers;
};
const _getLastPage = (currentPage, numTotalPages, numberPageButtonsOnPagination) => {
    const leftHandSide = Math.floor(numberPageButtonsOnPagination / 2);
    const rightHandSide = leftHandSide;
    if (currentPage + rightHandSide > numTotalPages) {
        return numTotalPages;
    }
    else if (currentPage + leftHandSide <= numberPageButtonsOnPagination) {
        return numberPageButtonsOnPagination;
    }
    else {
        return currentPage + rightHandSide;
    }
};
const _getFirstPage = (lastPage, numberPageButtonsOnPagination) => {
    if (lastPage - numberPageButtonsOnPagination + 1 > 0) {
        return lastPage - numberPageButtonsOnPagination + 1;
    }
    else {
        return 1;
    }
};
const _range = (size, startAt = 0) => new Array(size).fill(null).map((_, i) => i + startAt);

export { getNumberOfPages, getPageRangeList };
