text: "use strict";
  
  Object.defineProperty(exports, "__esModule", {
    value: true
  });
  exports.getPaginationParam = getPaginationParam;
  exports["default"] = usePagination;
  exports.DEFAULT_PAGE_SIZE = void 0;
  
  var _react = require("react");
  
  function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
  
  function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
  
  function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
  
  function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
  
  function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
  
  function _iterableToArrayLimit(arr, i) { if (typeof Symbol === "undefined" || !(Symbol.iterator in Object(arr))) return; var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
  
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
  
  function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  
  var __rest = void 0 && (void 0).__rest || function (s, e) {
    var t = {};
  
    for (var p in s) {
      if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
    }
  
    if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
      if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
    }
    return t;
  };
  
  var DEFAULT_PAGE_SIZE = 10;
  exports.DEFAULT_PAGE_SIZE = DEFAULT_PAGE_SIZE;
  
  function getPaginationParam(pagination, mergedPagination) {
    var param = {
      current: mergedPagination.current,
      pageSize: mergedPagination.pageSize
    };
    var paginationObj = pagination && _typeof(pagination) === 'object' ? pagination : {};
    Object.keys(paginationObj).forEach(function (pageProp) {
      var value = mergedPagination[pageProp];
  
      if (typeof value !== 'function') {
        param[pageProp] = value;
      }
    });
    return param;
  }
  
  function extendsObject() {
    var result = {};
  
    for (var _len = arguments.length, list = new Array(_len), _key = 0; _key < _len; _key++) {
      list[_key] = arguments[_key];
    }
  
    list.forEach(function (obj) {
      if (obj) {
        Object.keys(obj).forEach(function (key) {
          var val = obj[key];
  
          if (val !== undefined) {
            result[key] = val;
          }
        });
      }
    });
    return result;
  }
  
  function usePagination(total, pagination, onChange) {
    var _a = pagination && _typeof(pagination) === 'object' ? pagination : {},
        _a$total = _a.total,
        paginationTotal = _a$total === void 0 ? 0 : _a$total,
        paginationObj = __rest(_a, ["total"]);
  
    var _useState = (0, _react.useState)(function () {
      return {
        current: 'defaultCurrent' in paginationObj ? paginationObj.defaultCurrent : 1,
        pageSize: 'defaultPageSize' in paginationObj ? paginationObj.defaultPageSize : DEFAULT_PAGE_SIZE
      };
    }),
        _useState2 = _slicedToArray(_useState, 2),
        innerPagination = _useState2[0],
        setInnerPagination = _useState2[1]; // ============ Basic Pagination Config ============
  
  
    var mergedPagination = extendsObject(innerPagination, paginationObj, {
      total: paginationTotal > 0 ? paginationTotal : total
    });
  
    if (!paginationTotal) {
      // Reset `current` if data length changed. Only reset when paginationObj do not have total
      var maxPage = Math.ceil(total / mergedPagination.pageSize);
  
      if (maxPage < mergedPagination.current) {
        mergedPagination.current = 1;
      }
    }
  
    var refreshPagination = function refreshPagination() {
      var current = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1;
      setInnerPagination(_extends(_extends({}, mergedPagination), {
        current: current
      }));
    };
  
    var onInternalChange = function onInternalChange() {
      for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
        args[_key2] = arguments[_key2];
      }
  
      var current = args[0];
      refreshPagination(current);
      onChange(current, args[1] || mergedPagination.pageSize);
  
      if (pagination && pagination.onChange) {
        pagination.onChange.apply(pagination, args);
      }
    };
  
    var onInternalShowSizeChange = function onInternalShowSizeChange() {
      for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
        args[_key3] = arguments[_key3];
      }
  
      var pageSize = args[1];
      setInnerPagination(_extends(_extends({}, mergedPagination), {
        current: 1,
        pageSize: pageSize
      }));
      onChange(1, pageSize);
  
      if (pagination && pagination.onShowSizeChange) {
        pagination.onShowSizeChange.apply(pagination, args);
      }
    };
  
    if (pagination === false) {
      return [{}, function () {}];
    }
  
    return [_extends(_extends({}, mergedPagination), {
      onChange: onInternalChange,
      onShowSizeChange: onInternalShowSizeChange
    }), refreshPagination];
  }