"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];

var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard")["default"];

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = void 0;

var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));

var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));

var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));

var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));

var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));

var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));

var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));

var _createSuper2 = _interopRequireDefault(require("@babel/runtime/helpers/createSuper"));

var _react = _interopRequireWildcard(require("react"));

var _classnames = _interopRequireDefault(require("classnames"));

var _enum = require("../_util/enum");

var _LocaleReceiver = _interopRequireDefault(require("../locale-provider/LocaleReceiver"));

var _select = _interopRequireDefault(require("../select"));

var _MiniSelect = _interopRequireDefault(require("./MiniSelect"));

var _LargeSelect = _interopRequireDefault(require("./LargeSelect"));

var _pagination = _interopRequireDefault(require("../rc-components/pagination"));

var _en_US = _interopRequireDefault(require("../rc-components/pagination/locale/en_US"));

var _Button = _interopRequireDefault(require("../button/Button"));

var _ConfigContext = _interopRequireDefault(require("../config-provider/ConfigContext"));

var _excluded = ["className", "size", "locale", "prefixCls", "selectPrefixCls", "selectProps"];

function getSelect(size) {
  switch (size) {
    case _enum.Size.small:
      return _MiniSelect["default"];

    case _enum.Size.large:
      return _LargeSelect["default"];

    default:
      return _select["default"];
  }
}

function getIcon(type) {
  switch (type) {
    case 'first':
      return 'first_page';

    case 'last':
      return 'last_page';

    case 'prev':
      return 'navigate_before';

    case 'next':
      return 'navigate_next';

    default:
  }
}

function itemRender(page, type, item, disabled, size) {
  if (page !== undefined) {
    if (type === 'page' || type === 'jump-prev' || type === 'jump-next') {
      return /*#__PURE__*/_react["default"].createElement(_Button["default"], {
        size: size,
        shape: "circle"
      }, item);
    }

    return /*#__PURE__*/_react["default"].createElement(_Button["default"], {
      size: size,
      shape: "circle",
      icon: getIcon(type),
      disabled: disabled
    });
  }
}

var Pagination = /*#__PURE__*/function (_Component) {
  (0, _inherits2["default"])(Pagination, _Component);

  var _super = (0, _createSuper2["default"])(Pagination);

  function Pagination() {
    var _this;

    (0, _classCallCheck2["default"])(this, Pagination);
    _this = _super.apply(this, arguments);

    _this.renderPagination = function (contextLocale) {
      var _this$props = _this.props,
          className = _this$props.className,
          size = _this$props.size,
          customLocale = _this$props.locale,
          customizePrefixCls = _this$props.prefixCls,
          customizeSelectPrefixCls = _this$props.selectPrefixCls,
          _this$props$selectPro = _this$props.selectProps,
          selectProps = _this$props$selectPro === void 0 ? {} : _this$props$selectPro,
          restProps = (0, _objectWithoutProperties2["default"])(_this$props, _excluded);
      var _this$context = _this.context,
          getPrefixCls = _this$context.getPrefixCls,
          getConfig = _this$context.getConfig;
      var prefixCls = getPrefixCls('pagination', customizePrefixCls);
      selectProps.prefixCls = selectProps.prefixCls || getPrefixCls('select', customizeSelectPrefixCls);
      var locale = (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, contextLocale), customLocale);
      var isSmall = size === _enum.Size.small;
      var pageProps = getConfig('pagination');
      return /*#__PURE__*/_react["default"].createElement(_pagination["default"], (0, _extends2["default"])({}, pageProps, restProps, {
        selectProps: selectProps,
        prefixCls: prefixCls,
        size: size,
        className: (0, _classnames["default"])(className, (0, _defineProperty2["default"])({}, "".concat(prefixCls, "-").concat(size), size), {
          mini: isSmall
        }),
        selectComponentClass: getSelect(size),
        locale: locale
      }));
    };

    return _this;
  }

  (0, _createClass2["default"])(Pagination, [{
    key: "render",
    value: function render() {
      return /*#__PURE__*/_react["default"].createElement(_LocaleReceiver["default"], {
        componentName: "Pagination",
        defaultLocale: _en_US["default"]
      }, this.renderPagination);
    }
  }], [{
    key: "contextType",
    get: function get() {
      return _ConfigContext["default"];
    }
  }]);
  return Pagination;
}(_react.Component);

exports["default"] = Pagination;
Pagination.displayName = 'Pagination';
Pagination.defaultProps = {
  showSizeChanger: true,
  showSizeChangerLabel: true,
  tiny: true,
  pageSizeOptions: ['10', '30', '50', '100', '200'],
  showTotal: function showTotal(total, range) {
    return "".concat(range[0], " - ").concat(range[1], " / ").concat(total);
  },
  sizeChangerOptionText: function sizeChangerOptionText(value) {
    return value;
  },
  itemRender: itemRender
};
//# sourceMappingURL=Pagination.js.map
