"use strict";
const React = require("react");
const input = require("../Input/input.js");
const is = require("../_util/is.js");
const index = require("../ConfigProvider/index.js");
const emotionReactJsxRuntime_browser_esm = require("../../../../../../@emotion_react@11.10.4_3toe27fv7etiytxb5kxc7fxaw4/node_modules/@emotion/react/jsx-runtime/dist/emotion-react-jsx-runtime.browser.esm.js");
var __assign = globalThis && globalThis.__assign || function() {
  __assign = Object.assign || function(t) {
    for (var s, i = 1, n = arguments.length; i < n; i++) {
      s = arguments[i];
      for (var p in s)
        if (Object.prototype.hasOwnProperty.call(s, p))
          t[p] = s[p];
    }
    return t;
  };
  return __assign.apply(this, arguments);
};
var __read = globalThis && globalThis.__read || function(o, n) {
  var m = typeof Symbol === "function" && o[Symbol.iterator];
  if (!m)
    return o;
  var i = m.call(o), r, ar = [], e;
  try {
    while ((n === void 0 || n-- > 0) && !(r = i.next()).done)
      ar.push(r.value);
  } catch (error) {
    e = {
      error
    };
  } finally {
    try {
      if (r && !r.done && (m = i["return"]))
        m.call(i);
    } finally {
      if (e)
        throw e.error;
    }
  }
  return ar;
};
function PageJumper(props) {
  var defaultInputText = props.simple ? props.current : void 0;
  var locale = React.useContext(index.ConfigContext).locale;
  var _a = __read(React.useState(defaultInputText), 2), inputText = _a[0], setInputText = _a[1];
  var inputRef = React.useRef();
  React.useEffect(function() {
    if (props.simple) {
      setInputText(props.current);
    }
  }, [props.simple, props.current]);
  var handleChange = function(val) {
    var value = parseInt(val, 10);
    setInputText(isNaN(value) ? void 0 : value);
  };
  var handleJump = function() {
    var onPageChange = props.onPageChange, totalPages2 = props.totalPages, current = props.current, simple2 = props.simple;
    if (is.isUndefined(inputText)) {
      return;
    }
    if (inputText === current && !simple2) {
      setInputText(void 0);
      return;
    }
    var page = isNaN(Number(inputText)) ? current : Number(inputText);
    if (page < 1) {
      page = 1;
    } else if (page > totalPages2) {
      page = totalPages2;
    }
    setInputText(simple2 ? page : void 0);
    is.isFunction(onPageChange) && onPageChange(page);
  };
  var onFocus = function() {
    var input2 = inputRef.current.dom;
    if (String(inputText) && input2) {
      input2.setSelectionRange(0, String(inputText).length);
    }
  };
  var rootPrefixCls = props.rootPrefixCls, totalPages = props.totalPages, simple = props.simple, size = props.size, disabled = props.disabled;
  var prefixCls = rootPrefixCls + "-jumper";
  var inputConfig = __assign({
    showJumper: true
  }, is.isObject(simple) ? simple : {});
  return /* @__PURE__ */ emotionReactJsxRuntime_browser_esm.jsxs("div", {
    className: "" + prefixCls,
    children: [!simple && /* @__PURE__ */ emotionReactJsxRuntime_browser_esm.jsx("span", {
      className: prefixCls + "-text-goto",
      children: locale.Pagination.goto
    }), inputConfig.showJumper ? /* @__PURE__ */ emotionReactJsxRuntime_browser_esm.jsx(input.default, {
      _ignorePropsFromGlobal: true,
      ref: function(ref) {
        return inputRef.current = ref;
      },
      className: prefixCls + "-input",
      value: !is.isUndefined(inputText) ? inputText.toString() : void 0,
      size,
      disabled: disabled || !totalPages,
      onChange: handleChange,
      onPressEnter: handleJump,
      onFocus,
      onBlur: handleJump
    }) : /* @__PURE__ */ emotionReactJsxRuntime_browser_esm.jsx("span", {
      children: inputText
    }), simple && /* @__PURE__ */ emotionReactJsxRuntime_browser_esm.jsxs(emotionReactJsxRuntime_browser_esm.Fragment, {
      children: [/* @__PURE__ */ emotionReactJsxRuntime_browser_esm.jsx("span", {
        className: prefixCls + "-separator",
        children: "/"
      }), /* @__PURE__ */ emotionReactJsxRuntime_browser_esm.jsx("span", {
        children: totalPages
      })]
    })]
  });
}
module.exports = PageJumper;
//# sourceMappingURL=page-jumper.js.map
