import S from "../../@babel/runtime/helpers/esm/defineProperty.mjs";
import P from "../../@babel/runtime/helpers/esm/extends.mjs";
import xt from "../../@babel/runtime/helpers/esm/objectSpread2.mjs";
import Y from "../../@babel/runtime/helpers/esm/slicedToArray.mjs";
import C from "../../classnames/index.mjs";
import $e from "../../rc-util/es/hooks/useMergedState.mjs";
import p from "../../rc-util/es/KeyCode.mjs";
import yt from "../../rc-util/es/pickAttrs.mjs";
import { warningOnce as St } from "../../rc-util/es/warning.mjs";
import r, { useEffect as Pt } from "react";
import _t from "./locale/zh_CN.mjs";
import wt from "./Options.mjs";
import $ from "./Pager.mjs";
var bt = function(t, g, y) {
  return y;
};
function X() {
}
function Me(x) {
  var t = Number(x);
  return typeof t == "number" && !Number.isNaN(t) && isFinite(t) && Math.floor(t) === t;
}
function E(x, t, g) {
  var y = typeof x > "u" ? t : x;
  return Math.floor((g - 1) / y) + 1;
}
var kt = function(t) {
  var g, y = t.prefixCls, o = y === void 0 ? "rc-pagination" : y, Z = t.selectPrefixCls, Oe = Z === void 0 ? "rc-select" : Z, Be = t.className, Te = t.selectComponentClass, Ve = t.current, ee = t.defaultCurrent, Ke = ee === void 0 ? 1 : ee, te = t.total, u = te === void 0 ? 0 : te, Je = t.pageSize, ae = t.defaultPageSize, De = ae === void 0 ? 10 : ae, ne = t.onChange, h = ne === void 0 ? X : ne, Ae = t.hideOnSinglePage, re = t.showPrevNextJumpers, Ue = re === void 0 ? !0 : re, H = t.showQuickJumper, _ = t.showLessItems, oe = t.showTitle, N = oe === void 0 ? !0 : oe, le = t.onShowSizeChange, L = le === void 0 ? X : le, ie = t.locale, f = ie === void 0 ? _t : ie, He = t.style, ue = t.totalBoundaryShowSizeChanger, Le = ue === void 0 ? 50 : ue, M = t.disabled, O = t.simple, ce = t.showTotal, Q = t.showSizeChanger, Qe = t.pageSizeOptions, se = t.itemRender, w = se === void 0 ? bt : se, me = t.jumpPrevIcon, fe = t.jumpNextIcon, Ge = t.prevIcon, We = t.nextIcon, qe = r.useRef(null), Fe = $e(10, {
    value: Je,
    defaultValue: De
  }), de = Y(Fe, 2), s = de[0], Ye = de[1], Xe = $e(1, {
    value: Ve,
    defaultValue: Ke,
    postState: function(n) {
      return Math.max(1, Math.min(n, E(void 0, s, u)));
    }
  }), ve = Y(Xe, 2), a = ve[0], pe = ve[1], Ze = r.useState(a), ge = Y(Ze, 2), b = ge[0], B = ge[1];
  Pt(function() {
    B(a);
  }, [a]);
  var et = h !== X, tt = "current" in t;
  process.env.NODE_ENV !== "production" && St(tt ? et : !0, "You provided a `current` prop to a Pagination component without an `onChange` handler. This will render a read-only component.");
  var he = Math.max(1, a - (_ ? 3 : 5)), Ne = Math.min(E(void 0, s, u), a + (_ ? 3 : 5));
  function T(e, n) {
    var l = e || /* @__PURE__ */ r.createElement("button", {
      type: "button",
      "aria-label": n,
      className: "".concat(o, "-item-link")
    });
    return typeof e == "function" && (l = /* @__PURE__ */ r.createElement(e, xt({}, t))), l;
  }
  function Ce(e) {
    var n = e.target.value, l = E(void 0, s, u), v;
    return n === "" ? v = n : Number.isNaN(Number(n)) ? v = b : n >= l ? v = l : v = Number(n), v;
  }
  function at(e) {
    return Me(e) && e !== a && Me(u) && u > 0;
  }
  var nt = u > s ? H : !1;
  function rt(e) {
    (e.keyCode === p.UP || e.keyCode === p.DOWN) && e.preventDefault();
  }
  function Ee(e) {
    var n = Ce(e);
    switch (n !== b && B(n), e.keyCode) {
      case p.ENTER:
        m(n);
        break;
      case p.UP:
        m(n - 1);
        break;
      case p.DOWN:
        m(n + 1);
        break;
    }
  }
  function ot(e) {
    m(Ce(e));
  }
  function lt(e) {
    var n = E(e, s, u), l = a > n && n !== 0 ? n : a;
    Ye(e), B(l), L == null || L(a, e), pe(l), h == null || h(l, e);
  }
  function m(e) {
    if (at(e) && !M) {
      var n = E(void 0, s, u), l = e;
      return e > n ? l = n : e < 1 && (l = 1), l !== b && B(l), pe(l), h == null || h(l, s), l;
    }
    return a;
  }
  var V = a > 1, K = a < E(void 0, s, u), it = Q ?? u > Le;
  function xe() {
    V && m(a - 1);
  }
  function ye() {
    K && m(a + 1);
  }
  function Se() {
    m(he);
  }
  function Pe() {
    m(Ne);
  }
  function k(e, n) {
    if (e.key === "Enter" || e.charCode === p.ENTER || e.keyCode === p.ENTER) {
      for (var l = arguments.length, v = new Array(l > 2 ? l - 2 : 0), U = 2; U < l; U++)
        v[U - 2] = arguments[U];
      n.apply(void 0, v);
    }
  }
  function ut(e) {
    k(e, xe);
  }
  function ct(e) {
    k(e, ye);
  }
  function st(e) {
    k(e, Se);
  }
  function mt(e) {
    k(e, Pe);
  }
  function ft(e) {
    var n = w(e, "prev", T(Ge, "prev page"));
    return /* @__PURE__ */ r.isValidElement(n) ? /* @__PURE__ */ r.cloneElement(n, {
      disabled: !V
    }) : n;
  }
  function dt(e) {
    var n = w(e, "next", T(We, "next page"));
    return /* @__PURE__ */ r.isValidElement(n) ? /* @__PURE__ */ r.cloneElement(n, {
      disabled: !K
    }) : n;
  }
  function _e(e) {
    (e.type === "click" || e.keyCode === p.ENTER) && m(b);
  }
  var we = null, vt = yt(t, {
    aria: !0,
    data: !0
  }), pt = ce && /* @__PURE__ */ r.createElement("li", {
    className: "".concat(o, "-total-text")
  }, ce(u, [u === 0 ? 0 : (a - 1) * s + 1, a * s > u ? u : a * s])), be = null, i = E(void 0, s, u);
  if (Ae && u <= s)
    return null;
  var c = [], I = {
    rootPrefixCls: o,
    onClick: m,
    onKeyPress: k,
    showTitle: N,
    itemRender: w,
    page: -1
  }, gt = a - 1 > 0 ? a - 1 : 0, ht = a + 1 < i ? a + 1 : i, ke = H && H.goButton, J = ke, Ie = null;
  O && (typeof ke == "boolean" && (J = /* @__PURE__ */ r.createElement("button", {
    type: "button",
    onClick: _e,
    onKeyUp: _e
  }, f.jump_to_confirm)), J = /* @__PURE__ */ r.createElement("li", {
    title: N ? "".concat(f.jump_to).concat(a, "/").concat(i) : null,
    className: "".concat(o, "-simple-pager")
  }, J), Ie = /* @__PURE__ */ r.createElement("li", {
    title: N ? "".concat(a, "/").concat(i) : null,
    className: "".concat(o, "-simple-pager")
  }, /* @__PURE__ */ r.createElement("input", {
    type: "text",
    value: b,
    disabled: M,
    onKeyDown: rt,
    onKeyUp: Ee,
    onChange: Ee,
    onBlur: ot,
    size: 3
  }), /* @__PURE__ */ r.createElement("span", {
    className: "".concat(o, "-slash")
  }, "/"), i));
  var d = _ ? 1 : 2;
  if (i <= 3 + d * 2) {
    i || c.push(/* @__PURE__ */ r.createElement($, P({}, I, {
      key: "noPager",
      page: 1,
      className: "".concat(o, "-item-disabled")
    })));
    for (var z = 1; z <= i; z += 1)
      c.push(/* @__PURE__ */ r.createElement($, P({}, I, {
        key: z,
        page: z,
        active: a === z
      })));
  } else {
    var Nt = _ ? f.prev_3 : f.prev_5, Ct = _ ? f.next_3 : f.next_5, ze = w(he, "jump-prev", T(me, "prev page")), je = w(Ne, "jump-next", T(fe, "next page"));
    Ue && (we = ze ? /* @__PURE__ */ r.createElement("li", {
      title: N ? Nt : null,
      key: "prev",
      onClick: Se,
      tabIndex: 0,
      onKeyDown: st,
      className: C("".concat(o, "-jump-prev"), S({}, "".concat(o, "-jump-prev-custom-icon"), !!me))
    }, ze) : null, be = je ? /* @__PURE__ */ r.createElement("li", {
      title: N ? Ct : null,
      key: "next",
      onClick: Pe,
      tabIndex: 0,
      onKeyDown: mt,
      className: C("".concat(o, "-jump-next"), S({}, "".concat(o, "-jump-next-custom-icon"), !!fe))
    }, je) : null);
    var G = Math.max(1, a - d), W = Math.min(a + d, i);
    a - 1 <= d && (W = 1 + d * 2), i - a <= d && (G = i - d * 2);
    for (var j = G; j <= W; j += 1)
      c.push(/* @__PURE__ */ r.createElement($, P({}, I, {
        key: j,
        page: j,
        active: a === j
      })));
    if (a - 1 >= d * 2 && a !== 1 + 2 && (c[0] = /* @__PURE__ */ r.cloneElement(c[0], {
      className: C("".concat(o, "-item-after-jump-prev"), c[0].props.className)
    }), c.unshift(we)), i - a >= d * 2 && a !== i - 2) {
      var Re = c[c.length - 1];
      c[c.length - 1] = /* @__PURE__ */ r.cloneElement(Re, {
        className: C("".concat(o, "-item-before-jump-next"), Re.props.className)
      }), c.push(be);
    }
    G !== 1 && c.unshift(/* @__PURE__ */ r.createElement($, P({}, I, {
      key: 1,
      page: 1
    }))), W !== i && c.push(/* @__PURE__ */ r.createElement($, P({}, I, {
      key: i,
      page: i
    })));
  }
  var D = ft(gt);
  if (D) {
    var q = !V || !i;
    D = /* @__PURE__ */ r.createElement("li", {
      title: N ? f.prev_page : null,
      onClick: xe,
      tabIndex: q ? null : 0,
      onKeyDown: ut,
      className: C("".concat(o, "-prev"), S({}, "".concat(o, "-disabled"), q)),
      "aria-disabled": q
    }, D);
  }
  var A = dt(ht);
  if (A) {
    var R, F;
    O ? (R = !K, F = V ? 0 : null) : (R = !K || !i, F = R ? null : 0), A = /* @__PURE__ */ r.createElement("li", {
      title: N ? f.next_page : null,
      onClick: ye,
      tabIndex: F,
      onKeyDown: ct,
      className: C("".concat(o, "-next"), S({}, "".concat(o, "-disabled"), R)),
      "aria-disabled": R
    }, A);
  }
  var Et = C(o, Be, (g = {}, S(g, "".concat(o, "-simple"), O), S(g, "".concat(o, "-disabled"), M), g));
  return /* @__PURE__ */ r.createElement("ul", P({
    className: Et,
    style: He,
    ref: qe
  }, vt), pt, D, O ? Ie : c, A, /* @__PURE__ */ r.createElement(wt, {
    locale: f,
    rootPrefixCls: o,
    disabled: M,
    selectComponentClass: Te,
    selectPrefixCls: Oe,
    changeSize: it ? lt : null,
    pageSize: s,
    pageSizeOptions: Qe,
    quickGo: nt ? m : null,
    goButton: J
  }));
};
process.env.NODE_ENV !== "production" && (kt.displayName = "Pagination");
export {
  kt as default
};
