'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var React = require('react');
var styles = require('../styles.js');
var constants = require('../constants.js');
var index = require('../../Pagination/index.js');
var index$1 = require('../../../utils/index.js');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var React__default = /*#__PURE__*/_interopDefaultLegacy(React);

const PaginatedFooter = ({ footer, currentPage, setCurrentPage, numberOfRows, variant, 'data-testid': dataTestId, 'data-trackid': dataTrackId, }) => {
    var _a, _b;
    const appendTestId = index$1.getId(dataTestId);
    const appendTrackId = index$1.getId(dataTrackId);
    React.useEffect(() => {
        if (footer.variant === 'pagination' &&
            footer.pagination &&
            typeof footer.pagination.onChangePage === 'function') {
            footer.pagination.onChangePage(currentPage);
        }
    }, [currentPage]);
    if (footer.variant === 'pagination') {
        return (React__default['default'].createElement(React__default['default'].Fragment, null,
            footer.pagination && footer.pagination.displayResults && (React__default['default'].createElement(styles.ResultsArea, { "data-testid": appendTestId('results'), "data-trackid": appendTrackId('results') },
                ((_a = footer.pagination.resultsText) === null || _a === void 0 ? void 0 : _a.indicator) ||
                    constants.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) ||
                    constants.defaultResultsText.preposition,
                ' ',
                footer.pagination.totalNumberOfItems || numberOfRows)),
            !footer.pagination.externalPagination && (React__default['default'].createElement(index.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 index$1.unitJSX;
};

exports['default'] = PaginatedFooter;
