"use strict";
var __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
    result["default"] = mod;
    return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
/* @flow */
const React = __importStar(require("react"));
{
    PaginationProps;
}
from;
'./types';
const classnames_1 = __importDefault(require("classnames"));
// import _ from 'lodash';
const prop_types_1 = __importDefault(require("prop-types"));
const rc_pagination_1 = __importDefault(require("rc-pagination"));
const en_US_1 = __importDefault(require("rc-pagination/lib/locale/en_US"));
// import 'rc-pagination/assets/index.css';
const withStyles_1 = __importDefault(require("components/hoc/withStyles"));
const ErrorBoundary_1 = __importDefault(require("components/hoc/ErrorBoundary"));
const styles_1 = __importDefault(require("./styles"));
class Pagination extends React.Component {
    constructor(props) {
        super(props);
        this.onChange = page => {
            this.setState({
                current: page,
            });
            if (this.props.onPageChange) {
                this.props.onPageChange(page);
            }
        };
        this.itemRender = (current, type, element) => {
            const { classes } = this.props;
            if (type === 'page') {
                return (React.createElement("div", { className: classnames_1.default(classes.page, current === this.state.current && 'active') }, current));
            }
            if (type === 'jump-prev') {
                return React.createElement("div", { className: classes.page }, "...");
            }
            if (type === 'jump-next') {
                return React.createElement("div", { className: classes.page }, "...");
            }
            if (type === 'prev') {
                return React.createElement("div", { className: classnames_1.default(classes.page, classes.prevBtn) }, "Prev");
            }
            if (type === 'next') {
                return React.createElement("div", { className: classnames_1.default(classes.page, classes.nextBtn) }, "Next");
            }
            return element;
        };
        this.state = {
            current: props.current || 1,
        };
    }
    componentDidUpdate(prevProps) {
        if (this.props.current !== prevProps.current) {
            this.setState({
                current: this.props.current,
            });
        }
    }
    render() {
        const { classes, total, pageSize } = this.props;
        const { current } = this.state;
        const startItem = (current - 1) * pageSize;
        const endItem = startItem + pageSize;
        return (React.createElement(ErrorBoundary_1.default, null,
            React.createElement("div", { className: classes.component },
                React.createElement(rc_pagination_1.default, { locale: en_US_1.default, onChange: this.onChange, current: this.state.current, total: total, pageSize: pageSize, itemRender: this.itemRender, showLessItems: true }),
                React.createElement("div", { className: classes.numberWrapper },
                    startItem + 1,
                    "-",
                    endItem > total ? total : endItem,
                    " 0f ",
                    total))));
    }
}
Pagination.propTypes = {
    current: prop_types_1.default.number,
    pageSize: prop_types_1.default.number,
    total: prop_types_1.default.number.isRequired,
    onPageChange: prop_types_1.default.func,
    classes: prop_types_1.default.object,
};
Pagination.defaultProps = {
    pageSize: 10,
    onPageChange: () => { },
    current: 1,
};
exports.default = withStyles_1.default(styles_1.default)(Pagination);
//# sourceMappingURL=index.js.map