import React__default, { useEffect } from 'react';
import { ResultsArea } from '../styles.js';
import { defaultResultsText } from '../constants.js';
import { Pagination } from '../../Pagination/index.js';
import { unitJSX, getId } from '../../../utils/index.js';

const PaginatedFooter = ({ footer, currentPage, setCurrentPage, numberOfRows, variant, 'data-testid': dataTestId, 'data-trackid': dataTrackId, }) => {
    var _a, _b;
    const appendTestId = getId(dataTestId);
    const appendTrackId = getId(dataTrackId);
    useEffect(() => {
        if (footer.variant === 'pagination' &&
            footer.pagination &&
            typeof footer.pagination.onChangePage === 'function') {
            footer.pagination.onChangePage(currentPage);
        }
    }, [currentPage]);
    if (footer.variant === 'pagination') {
        return (React__default.createElement(React__default.Fragment, null,
            footer.pagination && footer.pagination.displayResults && (React__default.createElement(ResultsArea, { "data-testid": appendTestId('results'), "data-trackid": appendTrackId('results') },
                ((_a = footer.pagination.resultsText) === null || _a === void 0 ? void 0 : _a.indicator) ||
                    defaultResultsText.indicator,
                ' ',
                currentPage * footer.pagination.rowsPerPage -
                    footer.pagination.rowsPerPage +
                    1,
                ' ',
                "- ",
                currentPage * footer.pagination.rowsPerPage,
                ' ',
                ((_b = footer.pagination.resultsText) === null || _b === void 0 ? void 0 : _b.preposition) ||
                    defaultResultsText.preposition,
                ' ',
                footer.pagination.totalNumberOfItems || numberOfRows)),
            !footer.pagination.externalPagination && (React__default.createElement(Pagination, { variant: variant, currentPage: currentPage, rowsPerPage: footer.pagination.rowsPerPage, totalItems: footer.pagination.totalNumberOfItems || numberOfRows, paginationLimiter: footer.pagination.widePaginationLimiter, onChangePage: setCurrentPage, "data-testid": appendTestId(), "data-trackid": appendTrackId() }))));
    }
    return unitJSX;
};

export { PaginatedFooter as default };
