import { jsxs as _jsxs, jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
import { useEffect, useState } from "react";
import "./style.scss";
import clsx from "clsx";
const TablePagination = ({ totalCount = 50, lowerCap = 1, upperCap = 25, currentPage = 1, totalPages, onPrevClick = () => { }, onNextClick = () => { }, onPageNumberClick = () => { }, buttonsDisabled = false, dataCy, showPlus = false, }) => {
    const [all, setAll] = useState(totalPages < 8 ? true : false);
    useEffect(() => {
        setAll(totalPages < 8 ? true : false);
    }, [totalPages]);
    return (_jsxs("div", { className: "tablePagination", "data-cy": dataCy, children: [_jsxs("p", { children: [" ", lowerCap, "-", upperCap, " of ", totalCount.toLocaleString(), showPlus && totalCount === 1000 ? "+" : "", " "] }), _jsxs("span", { className: "tablePagination-ButtonGroup", children: [_jsx("button", { className: currentPage === 1 || buttonsDisabled ? "disable-cursor" : "", onClick: onPrevClick, disabled: currentPage === 1 || buttonsDisabled, children: "Previous" }), all &&
                        totalPages < 8 &&
                        Array.from({ length: totalPages }, (_, index) => index + 1).map((button, index) => {
                            return (_jsx("button", { disabled: buttonsDisabled, className: clsx({
                                    "disable-cursor": buttonsDisabled,
                                    currPage: button === currentPage,
                                }), 
                                // className={button==currentPage ? 'currPage' : ''}
                                onClick: () => onPageNumberClick(button), children: button }, index));
                        }), !all && currentPage < 5 && (_jsxs(_Fragment, { children: [_jsx("button", { disabled: buttonsDisabled, className: currentPage == 1 ? "currPage" : "", onClick: () => onPageNumberClick(1), children: 1 }), _jsx("button", { disabled: buttonsDisabled, className: currentPage == 2 ? "currPage" : "", onClick: () => onPageNumberClick(2), children: 2 }), _jsx("button", { disabled: buttonsDisabled, className: currentPage == 3 ? "currPage" : "", onClick: () => onPageNumberClick(3), children: 3 }), _jsx("button", { disabled: buttonsDisabled, className: currentPage == 4 ? "currPage" : "", onClick: () => onPageNumberClick(4), children: 4 }), _jsx("button", { disabled: buttonsDisabled, onClick: () => onPageNumberClick(5), children: 5 }), _jsx("button", { disabled: true, className: "dot-cursor", children: "..." }), _jsx("button", { disabled: buttonsDisabled, onClick: () => onPageNumberClick(totalPages), children: totalPages })] })), !all && currentPage >= 5 && currentPage < totalPages - 3 && (_jsxs(_Fragment, { children: [_jsx("button", { disabled: buttonsDisabled, onClick: () => onPageNumberClick(1), children: 1 }), _jsx("button", { disabled: true, className: "dot-cursor", children: "..." }), _jsx("button", { disabled: buttonsDisabled, onClick: () => onPageNumberClick(currentPage - 1), children: currentPage - 1 }), _jsx("button", { disabled: buttonsDisabled, className: "currPage", onClick: () => onPageNumberClick(currentPage), children: currentPage }), _jsx("button", { disabled: buttonsDisabled, onClick: () => onPageNumberClick(currentPage + 1), children: currentPage + 1 }), _jsx("button", { disabled: true, className: "dot-cursor", children: "..." }), _jsx("button", { disabled: buttonsDisabled, onClick: () => onPageNumberClick(totalPages), children: totalPages })] })), !all && currentPage >= totalPages - 3 && (_jsxs(_Fragment, { children: [_jsx("button", { disabled: buttonsDisabled, onClick: () => onPageNumberClick(1), children: 1 }), _jsx("button", { disabled: true, className: "dot-cursor", children: "..." }), _jsx("button", { disabled: buttonsDisabled, onClick: () => onPageNumberClick(totalPages - 4), children: totalPages - 4 }), _jsx("button", { disabled: buttonsDisabled, className: currentPage == totalPages - 3 ? "currPage" : "", onClick: () => onPageNumberClick(totalPages - 3), children: totalPages - 3 }), _jsx("button", { disabled: buttonsDisabled, className: currentPage == totalPages - 2 ? "currPage" : "", onClick: () => onPageNumberClick(totalPages - 2), children: totalPages - 2 }), _jsx("button", { disabled: buttonsDisabled, className: currentPage == totalPages - 1 ? "currPage" : "", onClick: () => onPageNumberClick(totalPages - 1), children: totalPages - 1 }), _jsx("button", { disabled: buttonsDisabled, className: currentPage == totalPages ? "currPage" : "", onClick: () => onPageNumberClick(totalPages), children: totalPages })] })), _jsx("button", { className: currentPage === totalPages || buttonsDisabled
                            ? "disable-cursor"
                            : "", disabled: currentPage === totalPages || buttonsDisabled, onClick: onNextClick, children: "Next" })] })] }));
};
export default TablePagination;
