"use strict";
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
const React = require("react");
const classNames = require("../_util/classNames.js");
const index$3 = require("../../icon/react-icon/IconLeft/index.js");
const index$2 = require("../../icon/react-icon/IconRight/index.js");
const index$1 = require("../../icon/react-icon/IconMore/index.js");
const index = require("../ConfigProvider/index.js");
const useKeyboardEvent = require("../_util/hooks/useKeyboardEvent.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;
};
exports.StepType = void 0;
(function(StepType) {
  StepType[StepType["previous"] = 0] = "previous";
  StepType[StepType["next"] = 1] = "next";
})(exports.StepType || (exports.StepType = {}));
function Pager(props) {
  var _a;
  var locale = React.useContext(index.ConfigContext).locale;
  var getKeyboardEvents = useKeyboardEvent();
  var pageNum = props.pageNum, current = props.current, rootPrefixCls = props.rootPrefixCls, pageItemStyle = props.pageItemStyle, activePageItemStyle = props.activePageItemStyle, itemRender = props.itemRender;
  var prefixCls = rootPrefixCls + "-item";
  var isActive = current === pageNum;
  var classnames = classNames(prefixCls, isActive ? prefixCls + "-active" : "");
  var style = pageItemStyle;
  if (isActive) {
    style = __assign(__assign({}, style), activePageItemStyle);
  }
  var ariaCurrentProps = isActive ? {
    "aria-current": true
  } : {};
  var onClick = function(e) {
    var pageNum2 = props.pageNum, onClick2 = props.onClick, disabled = props.disabled;
    if (e.currentTarget.dataset.active === "true") {
      return;
    }
    e.stopPropagation();
    if (!disabled) {
      onClick2 && onClick2(pageNum2);
    }
  };
  return /* @__PURE__ */ emotionReactJsxRuntime_browser_esm.jsx("li", {
    ...__assign({
      style,
      className: classnames,
      onClick,
      tabIndex: props.disabled ? -1 : 0,
      "aria-label": (_a = locale.Pagination.currentPage) === null || _a === void 0 ? void 0 : _a.replace("{0}", pageNum)
    }, getKeyboardEvents({
      onPressEnter: onClick
    }), ariaCurrentProps),
    children: itemRender ? itemRender(pageNum, "page", pageNum) : pageNum
  });
}
function getIcon(name, icons) {
  switch (name) {
    case "prev":
      return icons && icons.prev ? icons.prev : /* @__PURE__ */ emotionReactJsxRuntime_browser_esm.jsx(index$3, {});
    case "next":
      return icons && icons.next ? icons.next : /* @__PURE__ */ emotionReactJsxRuntime_browser_esm.jsx(index$2, {});
    case "more":
      return icons && icons.more ? icons.more : /* @__PURE__ */ emotionReactJsxRuntime_browser_esm.jsx(index$1, {});
    default:
      return null;
  }
}
var JumpPager = function(props) {
  var _a, _b;
  var locale = React.useContext(index.ConfigContext).locale;
  var rootPrefixCls = props.rootPrefixCls, current = props.current, allPages = props.allPages, jumpPage = props.jumpPage, icons = props.icons, disabled = props.disabled, pageItemStyle = props.pageItemStyle, itemRender = props.itemRender;
  var minCurrent = allPages > 0 ? 1 : 0;
  var nextPage = Math.min(allPages, Math.max(minCurrent, current + jumpPage));
  var prefix = rootPrefixCls + "-item " + rootPrefixCls + "-item-jumper";
  var cls = classNames(prefix);
  var onClick = function() {
    !disabled && props.onClick && props.onClick(nextPage);
  };
  var originElement = getIcon("more", icons);
  var ariaLabel = jumpPage > 0 ? (_a = locale.Pagination.nextSomePages) === null || _a === void 0 ? void 0 : _a.replace("{0}", jumpPage) : (_b = locale.Pagination.prevSomePages) === null || _b === void 0 ? void 0 : _b.replace("{0}", -jumpPage);
  return /* @__PURE__ */ emotionReactJsxRuntime_browser_esm.jsx("li", {
    style: pageItemStyle,
    className: cls,
    onClick,
    "aria-label": ariaLabel,
    children: itemRender ? itemRender(void 0, "more", originElement) : originElement
  });
};
var StepPager = function(props) {
  var _a;
  var _b = React.useContext(index.ConfigContext), locale = _b.locale, rtl = _b.rtl;
  var getKeyboardEvents = useKeyboardEvent();
  var rootPrefixCls = props.rootPrefixCls, current = props.current, allPages = props.allPages, type = props.type, icons = props.icons, disabled = props.disabled, pageItemStyle = props.pageItemStyle, itemRender = props.itemRender;
  var prefixCls = rootPrefixCls + "-item";
  var _c = __read(rtl ? ["next", "prev"] : ["prev", "next"], 2), prev = _c[0], next = _c[1];
  var StepIcon = type === exports.StepType.previous ? getIcon(prev, icons) : getIcon(next, icons);
  var _disabled = false;
  if (allPages === 0) {
    _disabled = true;
  } else if (type === exports.StepType.previous) {
    _disabled = current <= 1;
  } else {
    _disabled = current === allPages;
  }
  var innerDisabled = disabled || _disabled;
  var nextPage = current + (type === exports.StepType.previous ? -1 : 1);
  nextPage = Math.max(0, Math.min(allPages, nextPage));
  var pageType = exports.StepType.previous === type ? "prev" : "next";
  var cls = classNames(prefixCls, prefixCls + "-" + pageType, (_a = {}, _a[prefixCls + "-disabled"] = innerDisabled, _a));
  var onClick = function() {
    if (innerDisabled) {
      return;
    }
    props.onClick && props.onClick(nextPage);
  };
  return /* @__PURE__ */ emotionReactJsxRuntime_browser_esm.jsx("li", {
    ...__assign({
      style: pageItemStyle,
      className: cls,
      onClick,
      tabIndex: innerDisabled ? -1 : 0,
      "aria-label": locale.Pagination[pageType]
    }, getKeyboardEvents({
      onPressEnter: onClick
    })),
    children: itemRender ? itemRender(void 0, pageType, StepIcon) : StepIcon
  });
};
exports.JumpPager = JumpPager;
exports.StepPager = StepPager;
exports.default = Pager;
//# sourceMappingURL=page-item.js.map
