var __assign = (this && this.__assign) || function () {
    __assign = Object.assign || function(t) {
        for (var s, i = 1, n = arguments.length; i < n; i++) {
            s = arguments[i];
            for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
                t[p] = s[p];
        }
        return t;
    };
    return __assign.apply(this, arguments);
};
import React, { useCallback, memo } from 'react';
import { nthArg, pipe, pathOr, identity } from 'ramda';
import classnames from 'classnames';
import i18n from 'ui-i18n';
import { getValue } from '../helpers/events';
import TablePagination from '@mui/material/TablePagination';
import { useStyles } from './styles';
var BasicTablePagination = function (_a) {
    var _b = _a.classes, classes = _b === void 0 ? {} : _b, count = _a.count, rowsPerPageOptions = _a.rowsPerPageOptions, page = _a.page, onChangePage = _a.onChangePage, rowsPerPage = _a.rowsPerPage, onChangeRowsPerPage = _a.onChangeRowsPerPage, basicTableRef = _a.basicTableRef, labelRowsPerPage = _a.labelRowsPerPage;
    var styles = useStyles();
    var labelDisplayedRows = function (_a) {
        var from = _a.from, to = _a.to, count = _a.count;
        return i18n.text('${fromRow}-${toRow} of ${countRows}', {
            fromRow: i18n.number(from, '0,0'),
            toRow: i18n.number(to, '0,0'),
            countRows: i18n.number(count, '0,0')
        });
    };
    var resetScrollbarPosition = useCallback(function () {
        pathOr(identity, ['current', 'resetScrollbarPosition'], basicTableRef)();
    }, [basicTableRef]);
    var handleChangePage = useCallback(function (value) {
        onChangePage(value);
        resetScrollbarPosition();
    }, [onChangePage, resetScrollbarPosition]);
    var handleChangeRowsPerPage = useCallback(function (value) {
        onChangePage(0);
        onChangeRowsPerPage(value);
        resetScrollbarPosition();
    }, [onChangePage, onChangeRowsPerPage, resetScrollbarPosition]);
    return (React.createElement(TablePagination, { classes: __assign(__assign({}, classes), { root: classnames(styles.pagination, classes.root), select: classnames(styles.select, classes.select), selectLabel: classnames(styles.caption, classes.selectLabel), displayedRows: classnames(styles.displayedRows, classes.displayedRows), input: classnames(styles.selectRoot, classes.selectRoot), actions: styles.actions }), backIconButtonProps: { size: 'large' }, nextIconButtonProps: { size: 'large' }, component: "div", labelRowsPerPage: labelRowsPerPage || i18n.text('Rows per page:'), labelDisplayedRows: labelDisplayedRows, count: count, rowsPerPageOptions: rowsPerPageOptions, page: page, onPageChange: pipe(nthArg(1), handleChangePage), rowsPerPage: rowsPerPage, onRowsPerPageChange: pipe(getValue, handleChangeRowsPerPage) }));
};
BasicTablePagination.displayName = 'BasicTablePagination';
export default memo(BasicTablePagination);
