import React from "react";
import { Pagination } from "antd";
import { LeftOutlined, RightOutlined } from "@ant-design/icons";
import classNames from "classnames";
import Style from "./index.module.less";
function createDefaultTotal(t, total, newTotal, more, pageSize, currentPage, count, getTotal) {
    if (!total) {
        return t("totalCount", {
            count: 0,
        });
    }
    if (newTotal > total) {
        if (more && pageSize) {
            return t("totalCountMore", {
                count: newTotal - pageSize,
            });
        }
        if (pageSize &&
            currentPage &&
            typeof count === "number") {
            return t("totalCount", {
                count: (currentPage - 1) * pageSize + count,
            });
        }
    }
    if (typeof getTotal === "number" && newTotal >= getTotal) {
        return t("totalCountMore", {
            count: total,
        });
    }
    return t("totalCount", {
        count: total,
    });
}
export default function Render(props) {
    const { style, className, oakPagination, newTotal, showQuickJumper, showSizeChanger, size, showTotal, showTitle, } = props.data;
    const { setPageSize, setCurrentPage, t } = props.methods;
    const { pageSize = 0, total = 0, currentPage = 1, more, count, getTotal, } = oakPagination || {};
    if (!oakPagination || !total) {
        return null;
    }
    const shouldDisplayQuickJumper = newTotal > pageSize ? showQuickJumper : false;
    const itemRender = (_, type, originalElement) => {
        if (type === "prev") {
            return (<a>
                    <LeftOutlined />
                </a>);
        }
        if (type === "next") {
            return (<a>
                    <RightOutlined />
                </a>);
        }
        return originalElement;
    };
    const totalRenderer = (displayTotal, range) => {
        if (showTotal) {
            return showTotal(displayTotal, range);
        }
        return createDefaultTotal(t, total, newTotal, more, pageSize, currentPage, count, getTotal);
    };
    const paginationSize = size === "small" ? "small" : undefined;
    return (<Pagination style={style} className={classNames(className, Style.pagination, {
            [Style.paginationNoMore]: !more,
        })} itemRender={itemRender} pageSize={pageSize} total={newTotal} current={currentPage} showQuickJumper={shouldDisplayQuickJumper} showSizeChanger={showSizeChanger} size={paginationSize} showTotal={totalRenderer} showTitle={showTitle} onShowSizeChange={(_, nextPageSize) => {
            setPageSize(nextPageSize);
        }} onChange={(page, nextPageSize) => {
            if (nextPageSize !== pageSize) {
                return;
            }
            setCurrentPage(page);
        }}/>);
}
