import _Pagination from "@alifd/next/es/pagination";
import _extends from "@babel/runtime/helpers/extends";
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/objectWithoutPropertiesLoose";
import _inheritsLoose from "@babel/runtime/helpers/inheritsLoose";
var _excluded = ["pageSizeList", "paginationPosition"];
import React from "react";
import classnames from 'classnames';
import isString from "lodash/isString";
import { paginationProps, fetchKey } from "../utils/tableProps";
var WebPagination = /*#__PURE__*/function (_React$Component) {
  _inheritsLoose(WebPagination, _React$Component);
  function WebPagination() {
    return _React$Component.apply(this, arguments) || this;
  }
  var _proto = WebPagination.prototype;
  _proto.render = function render() {
    var _classnames;
    var _this$props = this.props,
      nextTablePrefix = _this$props.nextTablePrefix,
      currentPage = _this$props.currentPage,
      pageSize = _this$props.pageSize,
      totalCount = _this$props.totalCount,
      locale = _this$props.locale,
      onChange = _this$props.onChange,
      onPageSizeChange = _this$props.onPageSizeChange,
      hideOnlyOnePage = _this$props.hideOnlyOnePage,
      noPadding = _this$props.noPadding;
    var myProps = fetchKey(this.props, paginationProps);
    var pageSizeList = myProps.pageSizeList,
      _myProps$paginationPo = myProps.paginationPosition,
      paginationPosition = _myProps$paginationPo === void 0 ? 'right' : _myProps$paginationPo,
      rest = _objectWithoutPropertiesLoose(myProps, _excluded);
    if (hideOnlyOnePage && pageSize !== undefined && totalCount !== undefined && pageSize > totalCount) {
      return null;
    }
    return /*#__PURE__*/React.createElement("div", {
      className: classnames(nextTablePrefix + "web-pagination-wrap", (_classnames = {}, _classnames[nextTablePrefix + "no-padding"] = noPadding, _classnames))
    }, /*#__PURE__*/React.createElement(_Pagination, _extends({
      className: classnames(nextTablePrefix + "web-pagination", nextTablePrefix + "web-pagination-" + paginationPosition),
      totalRender: function totalRender(total) {
        return /*#__PURE__*/React.createElement("span", null, locale && locale.totalCount ? locale.totalCount : '总计', ":", ' ', total, ' ');
      }
    }, _extends({}, rest, {
      pageSizeList: pageSizeList && isString(pageSizeList) ? function () {
        var pageSizeArray = pageSizeList.split(',');
        if (pageSizeArray.length > 1) {
          return pageSizeArray.map(function (i) {
            return parseInt(i, 10);
          });
        }
      }() : pageSizeList,
      current: currentPage,
      pageSize: pageSize,
      total: totalCount,
      onChange: onChange,
      onPageSizeChange: onPageSizeChange
    }))), /*#__PURE__*/React.createElement("div", {
      style: {
        clear: 'both'
      }
    }));
  };
  return WebPagination;
}(React.Component);
export { WebPagination as default };