"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports["default"] = void 0;
exports.uuid = uuid;
var _configProvider = _interopRequireDefault(require("antd/lib/config-provider"));
var _pagination = _interopRequireDefault(require("antd/lib/pagination"));
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
var React = _interopRequireWildcard(require("react"));
require("./index.less");
var _zh_CN = _interopRequireDefault(require("antd/es/locale/zh_CN"));
var _excluded = ["simple", "size", "ifTotal", "wholeStyle", "flag", "disabled", "current", "defaultCurrent", "defaultPageSize", "showSizeChanger", "showQuickJumper", "hideOnSinglePage", "showLessItems", "pageSizeOptions", "total", "pageSize", "style"];
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
var antPagination = function antPagination(_ref) {
  var simple = _ref.simple,
    size = _ref.size,
    ifTotal = _ref.ifTotal,
    wholeStyle = _ref.wholeStyle,
    flag = _ref.flag,
    disabled = _ref.disabled,
    current = _ref.current,
    defaultCurrent = _ref.defaultCurrent,
    defaultPageSize = _ref.defaultPageSize,
    showSizeChanger = _ref.showSizeChanger,
    showQuickJumper = _ref.showQuickJumper,
    hideOnSinglePage = _ref.hideOnSinglePage,
    showLessItems = _ref.showLessItems,
    pageSizeOptions = _ref.pageSizeOptions,
    total = _ref.total,
    pageSize = _ref.pageSize,
    style = _ref.style,
    otherProps = (0, _objectWithoutPropertiesLoose2["default"])(_ref, _excluded);
  var yangshi = (0, _extends2["default"])({}, style);
  var _style = style || {};
  var newstyle = JSON.stringify(_style);
  var _otherProps = otherProps || {};
  // _otherProps.style = _style;
  _otherProps.style = (0, _extends2["default"])({}, _style);
  var arrObj = Object.keys(_otherProps.style);
  if (arrObj.length > 0) {
    for (var k in _otherProps.style) {
      if (k == 'paddingRight' || k == 'paddingLeft' || k == 'paddingTop' || k == 'paddingBottom' || k == 'marginRight' || k == 'marginLeft' || k == 'marginTop' || k == 'marginBottom') {
        _otherProps.style[k] = '0px';
      }
      if (k == 'width' || k == 'height') {
        _otherProps.style[k] = '100%';
      }
    }
  }
  var _useState = (0, React.useState)(''),
    ID = _useState[0],
    setID = _useState[1];
  (0, React.useEffect)(function () {
    setID("antPagination_" + uuid());
  }, []);
  (0, React.useEffect)(function () {
    ChangeSize();
  }, [ID, _otherProps]);
  var ChangeSize = function ChangeSize() {
    setTimeout(function () {
      if (ID) {
        var elemsMax = document.getElementById(ID) || document;
        newstyle = JSON.parse(newstyle);
        elemsMax.style.paddingRight = newstyle.paddingRight ? newstyle.paddingRight : 0;
        elemsMax.style.paddingLeft = newstyle.paddingLeft ? newstyle.paddingLeft : 0;
        elemsMax.style.paddingTop = newstyle.paddingTop ? newstyle.paddingTop : 0;
        elemsMax.style.paddingBottom = newstyle.paddingBottom ? newstyle.paddingBottom : 0;
        elemsMax.style.marginRight = newstyle.marginRight ? newstyle.marginRight : 0;
        elemsMax.style.marginLeft = newstyle.marginLeft ? newstyle.marginLeft : 0;
        elemsMax.style.marginTop = newstyle.marginTop ? newstyle.marginTop : 0;
        elemsMax.style.marginBottom = newstyle.marginBottom ? newstyle.marginBottom : 0;
      }
    }, 0);
  };
  (0, React.useEffect)(function () {
    if (ID) {
      preSelection();
      pitchOn();
      pagination();
      select();
    }
  });
  var preSelection = function preSelection() {
    document.getElementById(ID).style.setProperty('--agofontweight', wholeStyle.agostyle.weight);
    document.getElementById(ID).style.setProperty('--agobgcolor', wholeStyle.agostyle.background);
    document.getElementById(ID).style.setProperty('--agoborder', wholeStyle.agostyle.borderColor);
    document.getElementById(ID).style.setProperty('--agosize', wholeStyle.agostyle.size + 'px');
    document.getElementById(ID).style.setProperty('--agocoloor', wholeStyle.agostyle.color);
  };
  var pitchOn = function pitchOn() {
    document.getElementById(ID).style.setProperty('--laterfontweight', wholeStyle.laterstyle.weight);
    document.getElementById(ID).style.setProperty('--laterborder', wholeStyle.laterstyle.borderColor);
    document.getElementById(ID).style.setProperty('--laterbgcolor', wholeStyle.laterstyle.background);
    document.getElementById(ID).style.setProperty('--latersize', wholeStyle.laterstyle.size + 'px');
    document.getElementById(ID).style.setProperty('--latercoloor', wholeStyle.laterstyle.color);
  };
  var pagination = function pagination() {
    document.getElementById(ID).style.setProperty('--antprimarybordercolor', wholeStyle.hoverStyle.borderColor);
    document.getElementById(ID).style.setProperty('--antprimarybgcolor', wholeStyle.hoverStyle.background);
    document.getElementById(ID).style.setProperty('--antprimaryfontweight', wholeStyle.hoverStyle.weight);
    document.getElementById(ID).style.setProperty('--antprimarysize', wholeStyle.hoverStyle.size + 'px');
    document.getElementById(ID).style.setProperty('--antprimarycolor', wholeStyle.hoverStyle.color);
  };
  var select = function select() {
    document.getElementById(ID).style.setProperty('--selectcoloor', otherProps.style && otherProps.style.color ? otherProps.style.color : '');
    document.getElementById(ID).style.setProperty('--selectsize', otherProps.style && otherProps.style.fontSize ? otherProps.style.fontSize : '14px');
  };
  if (ifTotal) {
    otherProps.showTotal = function (total) {
      return "\u603B " + total + " \u6761";
    };
  }
  return (
    /*#__PURE__*/
    // <div id={ID} style={{ display: flag ? 'none' : 'inline-block' }} className='pagination'>
    React.createElement("div", {
      id: ID,
      style: {
        width: yangshi && yangshi.width ? yangshi.width : '',
        height: yangshi && yangshi.height ? yangshi.height : '',
        display: flag ? 'none' : 'inline-block'
      },
      className: "pagination"
    }, /*#__PURE__*/React.createElement(_configProvider["default"], {
      locale: _zh_CN["default"]
    }, /*#__PURE__*/React.createElement(_pagination["default"], (0, _extends2["default"])({
      simple: simple,
      size: size,
      current: current || 1,
      defaultCurrent: current || 1,
      defaultPageSize: defaultPageSize || 1,
      disabled: disabled,
      hideOnSinglePage: hideOnSinglePage,
      pageSize: pageSize || 1,
      pageSizeOptions: pageSizeOptions,
      total: total || 1,
      showSizeChanger: showSizeChanger,
      showQuickJumper: showQuickJumper,
      showLessItems: showLessItems
    }, _otherProps))))
  );
};
antPagination.displayName = 'antPagination';
var _default = antPagination;
exports["default"] = _default;
function uuid() {
  return (Math.random() * 1e6 >> 0).toString(36);
}