"use strict";
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);
};
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
    __setModuleDefault(result, mod);
    return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var react_1 = __importStar(require("react"));
var ramda_1 = require("ramda");
var classnames_1 = __importDefault(require("classnames"));
var ui_i18n_1 = __importDefault(require("ui-i18n"));
var events_1 = require("../helpers/events");
var TablePagination_1 = __importDefault(require("@mui/material/TablePagination"));
var styles_1 = require("./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 = (0, styles_1.useStyles)();
    var labelDisplayedRows = function (_a) {
        var from = _a.from, to = _a.to, count = _a.count;
        return ui_i18n_1.default.text('${fromRow}-${toRow} of ${countRows}', {
            fromRow: ui_i18n_1.default.number(from, '0,0'),
            toRow: ui_i18n_1.default.number(to, '0,0'),
            countRows: ui_i18n_1.default.number(count, '0,0')
        });
    };
    var resetScrollbarPosition = (0, react_1.useCallback)(function () {
        (0, ramda_1.pathOr)(ramda_1.identity, ['current', 'resetScrollbarPosition'], basicTableRef)();
    }, [basicTableRef]);
    var handleChangePage = (0, react_1.useCallback)(function (value) {
        onChangePage(value);
        resetScrollbarPosition();
    }, [onChangePage, resetScrollbarPosition]);
    var handleChangeRowsPerPage = (0, react_1.useCallback)(function (value) {
        onChangePage(0);
        onChangeRowsPerPage(value);
        resetScrollbarPosition();
    }, [onChangePage, onChangeRowsPerPage, resetScrollbarPosition]);
    return (react_1.default.createElement(TablePagination_1.default, { classes: __assign(__assign({}, classes), { root: (0, classnames_1.default)(styles.pagination, classes.root), select: (0, classnames_1.default)(styles.select, classes.select), selectLabel: (0, classnames_1.default)(styles.caption, classes.selectLabel), displayedRows: (0, classnames_1.default)(styles.displayedRows, classes.displayedRows), input: (0, classnames_1.default)(styles.selectRoot, classes.selectRoot), actions: styles.actions }), backIconButtonProps: { size: 'large' }, nextIconButtonProps: { size: 'large' }, component: "div", labelRowsPerPage: labelRowsPerPage || ui_i18n_1.default.text('Rows per page:'), labelDisplayedRows: labelDisplayedRows, count: count, rowsPerPageOptions: rowsPerPageOptions, page: page, onPageChange: (0, ramda_1.pipe)((0, ramda_1.nthArg)(1), handleChangePage), rowsPerPage: rowsPerPage, onRowsPerPageChange: (0, ramda_1.pipe)(events_1.getValue, handleChangeRowsPerPage) }));
};
BasicTablePagination.displayName = 'BasicTablePagination';
exports.default = (0, react_1.memo)(BasicTablePagination);
