"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.usePagination = usePagination;
const react_1 = require("react");
function usePagination({ total = 1 }) {
    const [page, _setPage] = (0, react_1.useState)(1);
    const [limit, _setLimit] = (0, react_1.useState)(10);
    const totalPages = Math.ceil(total / limit);
    const nextPage = () => {
        if (page + 1 > totalPages) {
            return;
        }
        _setPage((page) => page + 1);
    };
    const previousPage = () => {
        if (page - 1 < 1) {
            return;
        }
        _setPage((page) => page - 1);
    };
    const setPage = (page) => {
        if (page < 1 || page > totalPages) {
            return;
        }
        _setPage(page);
    };
    const setLimit = (limit) => {
        if (limit < 1) {
            return;
        }
        _setLimit(limit);
    };
    return {
        page,
        limit,
        setLimit,
        setPage,
        nextPage,
        previousPage
    };
}
