import { useState } from 'react';

const usePagination = ({ itemsCount, itemsPerPage })=>{
    const [currentPage, setCurrentPage] = useState(0);
    // keep current page clamped within range in case number of items shrinks
    const pageCount = Math.ceil(itemsCount / itemsPerPage);
    const lastPageIndex = Math.max(0, pageCount - 1);
    if (currentPage > lastPageIndex) {
        setCurrentPage(lastPageIndex);
    }
    return {
        currentPage,
        setCurrentPage
    };
};

export { usePagination };
//# sourceMappingURL=usePagination.mjs.map
