"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports["default"] = void 0;
var _pagination = _interopRequireDefault(require("@alifd/next/lib/pagination"));
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
var _inheritsLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/inheritsLoose"));
var _react = _interopRequireDefault(require("react"));
var _classnames2 = _interopRequireDefault(require("classnames"));
var _isString = _interopRequireDefault(require("lodash/isString"));
var _tableProps = require("../utils/tableProps");
var _excluded = ["pageSizeList", "paginationPosition"];
var WebPagination = /*#__PURE__*/function (_React$Component) {
  (0, _inheritsLoose2["default"])(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 = (0, _tableProps.fetchKey)(this.props, _tableProps.paginationProps);
    var pageSizeList = myProps.pageSizeList,
      _myProps$paginationPo = myProps.paginationPosition,
      paginationPosition = _myProps$paginationPo === void 0 ? 'right' : _myProps$paginationPo,
      rest = (0, _objectWithoutPropertiesLoose2["default"])(myProps, _excluded);
    if (hideOnlyOnePage && pageSize !== undefined && totalCount !== undefined && pageSize > totalCount) {
      return null;
    }
    return /*#__PURE__*/_react["default"].createElement("div", {
      className: (0, _classnames2["default"])(nextTablePrefix + "web-pagination-wrap", (_classnames = {}, _classnames[nextTablePrefix + "no-padding"] = noPadding, _classnames))
    }, /*#__PURE__*/_react["default"].createElement(_pagination["default"], (0, _extends2["default"])({
      className: (0, _classnames2["default"])(nextTablePrefix + "web-pagination", nextTablePrefix + "web-pagination-" + paginationPosition),
      totalRender: function totalRender(total) {
        return /*#__PURE__*/_react["default"].createElement("span", null, locale && locale.totalCount ? locale.totalCount : '总计', ":", ' ', total, ' ');
      }
    }, (0, _extends2["default"])({}, rest, {
      pageSizeList: pageSizeList && (0, _isString["default"])(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["default"].createElement("div", {
      style: {
        clear: 'both'
      }
    }));
  };
  return WebPagination;
}(_react["default"].Component);
exports["default"] = WebPagination;