import { faAngleRight, faAngleLeft } from '@fortawesome/free-solid-svg-icons';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import React, { useEffect, useState } from 'react';
function classNames(...classes) {
    return classes.filter(Boolean).join(' ');
}
const Pagination = ({ currentPage, handleChangePage, totalPages, rowQuantity, count, router }) => {
    const [searchParams, setSearchParams] = useState({});
    useEffect(() => {
        if (typeof window !== 'undefined') {
            const params = new URLSearchParams(window.location.search);
            setSearchParams(params);
        }
    }, []);
    const handleClickPage = (page, isAction) => {
        if (!isAction)
            return;
        handleChangePage(page);
        const params = new URLSearchParams(searchParams + '');
        params.set('pagi', page + '');
        router === null || router === void 0 ? void 0 : router.push(`?${params + ''}`, { scroll: false });
    };
    const disableNextPage = currentPage === totalPages;
    const disablePrevPage = currentPage === 1;
    const PreviousPage = () => (React.createElement("a", { "aria-hidden": true, className: classNames('relative inline-flex bg-gray-200 rounded-tl-lg pb-1 pt-0.5 rounded-bl-lg items-center px-3 text-gray-900 focus:z-20 focus:outline-offset-0 min-h-[1.75rem]', !disablePrevPage ? 'hover:bg-gray-300' : '', !disablePrevPage
            ? 'active:bg-gray-300 active:shadow-[0rem_0.125rem_0.1rem_0rem_#0004_inset] active:pt-[0.2rem] active:pb-[0.2rem]'
            : '', !disablePrevPage ? 'cursor-pointer' : ''), onClick: () => handleClickPage(currentPage - 1, !disablePrevPage) },
        React.createElement("p", null,
            React.createElement("span", { className: 'sr-only' }, "Previous"),
            React.createElement(FontAwesomeIcon, { className: classNames('w-2.5 h-3', disablePrevPage ? 'text-gray-300' : 'text-gray-900'), icon: faAngleLeft }))));
    const NextPage = () => (React.createElement("a", { "aria-hidden": true, className: classNames('relative inline-flex rounded-tr-lg bg-gray-200 pb-1 pt-0.5 rounded-br-lg items-center rounded-r-md px-3 text-gray-900 focus:z-20 focus:outline-offset-0 min-h-[1.75rem]', !disableNextPage ? 'hover:bg-gray-300' : '', !disableNextPage
            ? 'active:bg-gray-300 active:shadow-[0rem_0.125rem_0.1rem_0rem_#0004_inset] active:pt-[0.01rem] active:pb-[0.03rem]'
            : '', !disableNextPage ? 'cursor-pointer' : ''), onClick: () => handleClickPage(currentPage + 1, !disableNextPage) },
        React.createElement("p", null,
            React.createElement("span", { className: 'sr-only' }, "Next"),
            React.createElement(FontAwesomeIcon, { className: classNames('w-2.5 h-3', disableNextPage ? 'text-gray-300' : 'text-gray-900'), icon: faAngleRight }))));
    const startIndex = (currentPage - 1) * rowQuantity + 1;
    const endIndex = (currentPage - 1) * rowQuantity + rowQuantity;
    return (React.createElement("div", { className: 'flex items-center gap-x-3' },
        React.createElement("p", { className: 'hidden whitespace-nowrap text-xs sm:block' },
            "Hi\u1EC3n th\u1ECB ",
            startIndex,
            " - ",
            endIndex >= count ? count : endIndex,
            " tr\u00EAn ",
            count,
            " b\u1EA3n ghi"),
        React.createElement("div", { className: 'shadow-sm isolate inline-flex -space-x-px rounded-md bg-white' },
            React.createElement("div", { className: 'mr-1' },
                React.createElement(PreviousPage, null)),
            React.createElement(NextPage, null))));
};
export default Pagination;
//# sourceMappingURL=Pagination.js.map