/**
 * ldesign v0.3.13
 * (c) 2023 ldesign
 * @license MIT
 */

import { _ as _objectWithoutProperties } from '../_chunks/dep-60fae668.mjs';
import { _ as _slicedToArray } from '../_chunks/dep-84acf3c2.mjs';
import { isVNode, defineComponent, toRefs, ref, computed, watch, createVNode, mergeProps } from 'vue';
import '../_chunks/dep-eba0ea6e.mjs';
import { i as isNumber_1 } from '../_chunks/dep-3f21269a.mjs';
import { PageFirstIcon, PageLastIcon, ChevronLeftIcon, ChevronRightIcon, ChevronLeftDoubleIcon, ChevronRightDoubleIcon, EllipsisIcon } from '@ldesign/icons-vue-next';
import { i as isObject_1 } from '../_chunks/dep-a8bcacea.mjs';
import { usePrefixClass } from '../hooks/useConfig.mjs';
import { useGlobalIcon } from '../hooks/useGlobalIcon.mjs';
import { InputNumber } from '../input-number/index.mjs';
import { Select, Option } from '../select/index.mjs';
import { InputAdornment } from '../input-adornment/index.mjs';
import useVModel from '../hooks/useVModel.mjs';
import useDefaultValue from '../hooks/useDefaultValue.mjs';
import { useTNodeJSX } from '../hooks/tnode.mjs';
import props from './props.mjs';
import usePaginationClasses from './usePaginationClasses.mjs';
import useMoreAction from './useMoreAction.mjs';
import { useConfig } from '../config-provider/useConfig.mjs';
import '../_chunks/dep-b8d7992c.mjs';
import '../_chunks/dep-469b4ae0.mjs';
import '../_chunks/dep-255303ba.mjs';
import '../_chunks/dep-3da99438.mjs';
import '../utils/withInstall.mjs';
import '../input-number/input-number.mjs';
import '../_chunks/dep-2db7b3ec.mjs';
import '../button/index.mjs';
import '../button/button.mjs';
import '../_chunks/dep-bf1e33c8.mjs';
import '../loading/index.mjs';
import '../loading/directive.mjs';
import '../loading/plugin.mjs';
import '../utils/dom.mjs';
import '../_chunks/dep-876fb3ec.mjs';
import '../_chunks/dep-b57180d0.mjs';
import '../_chunks/dep-c8d7b6b4.mjs';
import '../_chunks/dep-5717e263.mjs';
import '../utils/easing.mjs';
import '../loading/loading.mjs';
import '../utils/render-tnode.mjs';
import '../_chunks/dep-888e80c4.mjs';
import '../_chunks/dep-334a4f6b.mjs';
import '../_chunks/dep-e5eb9f23.mjs';
import '../_chunks/dep-9fe2ef12.mjs';
import '../_chunks/dep-672e7d1a.mjs';
import '../_chunks/dep-4d7a675b.mjs';
import '../_chunks/dep-2e7f59b1.mjs';
import '../_chunks/dep-1434aa15.mjs';
import '../_chunks/dep-9262ee2f.mjs';
import '../_chunks/dep-406cd044.mjs';
import '../_chunks/dep-42cc3015.mjs';
import '../_chunks/dep-2bc37d52.mjs';
import '../_chunks/dep-327559e8.mjs';
import '../_chunks/dep-b2235f26.mjs';
import '../_chunks/dep-8b989474.mjs';
import '../_chunks/dep-1372b2d3.mjs';
import '../_chunks/dep-9a85dac1.mjs';
import '../hooks/useTeleport.mjs';
import '../loading/props.mjs';
import '../loading/icon/gradient.mjs';
import '../_common/js/loading/circle-adapter.mjs';
import '../_common/js/utils/set-style.mjs';
import '../_common/js/utils/helper.mjs';
import '../_chunks/dep-ed5ebb35.mjs';
import '../_chunks/dep-78847b2e.mjs';
import '../_chunks/dep-095107f7.mjs';
import '../_chunks/dep-c989dff3.mjs';
import '../_chunks/dep-9cf86cf1.mjs';
import '../_chunks/dep-bc1d737a.mjs';
import '../_chunks/dep-855db8bc.mjs';
import '../_chunks/dep-a87f3e4c.mjs';
import '../_chunks/dep-1e566bb5.mjs';
import '../_chunks/dep-42a19209.mjs';
import '../_chunks/dep-8d3e9aa3.mjs';
import '../_chunks/dep-40d69a9c.mjs';
import '../_chunks/dep-dcc83161.mjs';
import '../_chunks/dep-0fc02184.mjs';
import '../_chunks/dep-f1994936.mjs';
import '../_chunks/dep-345e1be3.mjs';
import '../_common/js/global-config/default-config.mjs';
import '../_common/js/global-config/locale/zh_CN.mjs';
import '../_chunks/dep-9888611c.mjs';
import '../_chunks/dep-697a1365.mjs';
import '../config-provider/type.mjs';
import '../loading/style/css.mjs';
import '../loading/type.mjs';
import '../hooks/useRipple.mjs';
import '../utils/set-style.mjs';
import '../hooks/useKeepAnimation.mjs';
import '../form/hooks.mjs';
import '../button/props.mjs';
import '../button/style/css.mjs';
import '../button/type.mjs';
import '../input/index.mjs';
import '../input/input.mjs';
import '../input/props.mjs';
import '../input/useInput.mjs';
import '../form/const.mjs';
import '../hooks/index.mjs';
import '../hooks/icon.mjs';
import '../hooks/slot.mjs';
import '../hooks/useCommonClassName.mjs';
import '../hooks/useDestroyOnClose.mjs';
import '../hooks/useVirtualScroll.mjs';
import '../input/useLengthLimit.mjs';
import '../_common/js/log/index.mjs';
import '../_common/js/log/log.mjs';
import '../input/useInputEventHandler.mjs';
import '../input/useInputWidth.mjs';
import '../input/input-group.mjs';
import '../input/input-group-props.mjs';
import '../input/style/css.mjs';
import '../input/type.mjs';
import '../input-number/props.mjs';
import '../input-number/useInputNumber.mjs';
import '../_common/js/input-number/number.mjs';
import '../_chunks/dep-01e3f446.mjs';
import '../_common/js/input-number/large-number.mjs';
import '../input-number/style/css.mjs';
import '../input-number/type.mjs';
import '../select/select.mjs';
import '../_chunks/dep-8932db97.mjs';
import '../_chunks/dep-0d3dd4b5.mjs';
import '../_chunks/dep-550c24c1.mjs';
import '../_chunks/dep-6884627f.mjs';
import '../_chunks/dep-9b6cf76d.mjs';
import '../_chunks/dep-f709f709.mjs';
import '../_chunks/dep-c81c0ee4.mjs';
import '../_chunks/dep-85ed244c.mjs';
import '../_chunks/dep-c42916c7.mjs';
import '../common-components/fake-arrow.mjs';
import '../select-input/index.mjs';
import '../select-input/select-input.mjs';
import '../popup/index.mjs';
import '../popup/popup.mjs';
import '@popperjs/core';
import '../popup/props.mjs';
import '../popup/container.mjs';
import '../hooks/useResizeObserver.mjs';
import '../popup/style/css.mjs';
import '../popup/type.mjs';
import '../select-input/props.mjs';
import '../select-input/useSingle.mjs';
import '../select-input/useMultiple.mjs';
import '../tag-input/index.mjs';
import '../tag-input/tag-input.mjs';
import '../tag-input/props.mjs';
import '../tag-input/hooks/useTagScroll.mjs';
import '../tag-input/useTagList.mjs';
import '../tag/index.mjs';
import '../tag/tag.mjs';
import '../tag/props.mjs';
import '../tag/check-tag.mjs';
import '../tag/check-tag-props.mjs';
import '../tag/style/css.mjs';
import '../tag/type.mjs';
import '../tag-input/hooks/useHover.mjs';
import '../tag-input/hooks/useDragSorter.mjs';
import '../tag-input/style/css.mjs';
import '../tag-input/type.mjs';
import '../select-input/useOverlayInnerStyle.mjs';
import '../select-input/style/css.mjs';
import '../select-input/type.mjs';
import '../select/props.mjs';
import '../select/select-panel.mjs';
import '../_chunks/dep-350764bc.mjs';
import '../select/option.mjs';
import '../checkbox/index.mjs';
import '../checkbox/checkbox.mjs';
import '../checkbox/props.mjs';
import '../checkbox/constants.mjs';
import '../checkbox/group.mjs';
import '../checkbox/checkbox-group-props.mjs';
import '../checkbox/style/css.mjs';
import '../checkbox/type.mjs';
import '../select/option-props.mjs';
import '../select/helper.mjs';
import '../select/optionGroup.mjs';
import '../select/option-group-props.mjs';
import '../select/hooks/usePanelVirtualScroll.mjs';
import '../select/hooks/useSelectOptions.mjs';
import '../select/style/css.mjs';
import '../select/type.mjs';
import '../input-adornment/input-adornment.mjs';
import '../input-adornment/props.mjs';
import '../input-adornment/style/css.mjs';
import '../input-adornment/type.mjs';

var isNumber = isNumber_1;

/**
 * Checks if `value` is `NaN`.
 *
 * **Note:** This method is based on
 * [`Number.isNaN`](https://mdn.io/Number/isNaN) and is not the same as
 * global [`isNaN`](https://mdn.io/isNaN) which returns `true` for
 * `undefined` and other non-number values.
 *
 * @static
 * @memberOf _
 * @since 0.1.0
 * @category Lang
 * @param {*} value The value to check.
 * @returns {boolean} Returns `true` if `value` is `NaN`, else `false`.
 * @example
 *
 * _.isNaN(NaN);
 * // => true
 *
 * _.isNaN(new Number(NaN));
 * // => true
 *
 * isNaN(undefined);
 * // => true
 *
 * _.isNaN(undefined);
 * // => false
 */
function isNaN(value) {
  // An `NaN` primitive is the only value that is not equal to itself.
  // Perform the `toStringTag` check first to avoid errors with some
  // ActiveX objects in IE.
  return isNumber(value) && value != +value;
}
var _isNaN = isNaN;

var _excluded = ["pageCount"];
function _isSlot(s) {
  return typeof s === 'function' || Object.prototype.toString.call(s) === '[object Object]' && !isVNode(s);
}
var min = 1;
var _Pagination = defineComponent({
  name: "TPagination",
  props: props,
  setup: function setup(props2) {
    var _toRefs = toRefs(props2),
      modelValue = _toRefs.modelValue,
      pageSize = _toRefs.pageSize,
      current = _toRefs.current;
    var renderTNodeJSX = useTNodeJSX();
    var _useVModel = useVModel(current, modelValue, props2.defaultCurrent, props2.onCurrentChange, "current"),
      _useVModel2 = _slicedToArray(_useVModel, 2),
      innerCurrent = _useVModel2[0],
      setInnerCurrent = _useVModel2[1];
    var _useDefaultValue = useDefaultValue(pageSize, props2.defaultPageSize, props2.onPageSizeChange, "pageSize"),
      _useDefaultValue2 = _slicedToArray(_useDefaultValue, 2),
      innerPageSize = _useDefaultValue2[0],
      setInnerPageSize = _useDefaultValue2[1];
    var _useConfig = useConfig("pagination"),
      t = _useConfig.t,
      globalConfig = _useConfig.globalConfig;
    var COMPONENT_NAME = usePrefixClass("pagination");
    var _useGlobalIcon = useGlobalIcon({
        PageFirstIcon: PageFirstIcon,
        PageLastIcon: PageLastIcon,
        ChevronLeftIcon: ChevronLeftIcon,
        ChevronRightIcon: ChevronRightIcon,
        ChevronLeftDoubleIcon: ChevronLeftDoubleIcon,
        ChevronRightDoubleIcon: ChevronRightDoubleIcon,
        EllipsisIcon: EllipsisIcon
      }),
      PageFirstIcon$1 = _useGlobalIcon.PageFirstIcon,
      PageLastIcon$1 = _useGlobalIcon.PageLastIcon,
      ChevronLeftIcon$1 = _useGlobalIcon.ChevronLeftIcon,
      ChevronRightIcon$1 = _useGlobalIcon.ChevronRightIcon,
      ChevronLeftDoubleIcon$1 = _useGlobalIcon.ChevronLeftDoubleIcon,
      ChevronRightDoubleIcon$1 = _useGlobalIcon.ChevronRightDoubleIcon,
      EllipsisIcon$1 = _useGlobalIcon.EllipsisIcon;
    var _usePaginationClasses = usePaginationClasses(props2, innerCurrent, innerPageSize, COMPONENT_NAME),
      pageCount = _usePaginationClasses.pageCount,
      CLASS_MAP = _objectWithoutProperties(_usePaginationClasses, _excluded);
    var _useMoreAction = useMoreAction(props2, pageCount, innerCurrent),
      prevMore = _useMoreAction.prevMore,
      isPrevMoreShow = _useMoreAction.isPrevMoreShow,
      curPageLeftCount = _useMoreAction.curPageLeftCount,
      nextMore = _useMoreAction.nextMore,
      isNextMoreShow = _useMoreAction.isNextMoreShow,
      curPageRightCount = _useMoreAction.curPageRightCount;
    var jumpIndex = ref(innerCurrent.value);
    var isFolded = computed(function () {
      return pageCount.value > props2.maxPageBtn;
    });
    var sizeOptions = computed(function () {
      var pageSizeOptions = props2.pageSizeOptions;
      var options = pageSizeOptions.map(function (option) {
        return isObject_1(option) ? option : {
          label: t(globalConfig.value.itemsPerPage, {
            size: option
          }),
          value: Number(option)
        };
      });
      return options.sort(function (a, b) {
        return a.value - b.value;
      });
    });
    var isMidEllipsis = computed(function () {
      return props2.pageEllipsisMode === "mid";
    });
    var pages = computed(function () {
      var array = [];
      var start;
      var end;
      if (isFolded.value) {
        if (isPrevMoreShow.value && isNextMoreShow.value) {
          start = innerCurrent.value - curPageLeftCount.value;
          end = innerCurrent.value + curPageRightCount.value;
        } else {
          var foldedStart = isMidEllipsis.value ? 2 : 1;
          var foldedEnd = isMidEllipsis.value ? pageCount.value - 1 : pageCount.value;
          start = isPrevMoreShow.value ? pageCount.value - props2.foldedMaxPageBtn + 1 : foldedStart;
          end = isPrevMoreShow.value ? foldedEnd : props2.foldedMaxPageBtn;
        }
      } else {
        start = 1;
        end = pageCount.value;
      }
      for (var i = start; i <= end; i++) array.push(i);
      return array;
    });
    watch(function () {
      return pageCount.value;
    }, function () {
      if (innerCurrent.value > pageCount.value) innerCurrent.value = 1;
    });
    watch(function () {
      return innerCurrent.value;
    }, function (val) {
      return jumpIndex.value = val;
    });
    var toPage = function toPage(pageIndex, isTriggerChange) {
      if (props2.disabled) return;
      var current2 = pageIndex;
      if (pageIndex < min) current2 = min;else if (pageIndex > pageCount.value) current2 = pageCount.value;
      if (innerCurrent.value !== current2) {
        var _props2$onChange;
        var prev = innerCurrent.value;
        var pageInfo = {
          current: current2,
          previous: prev,
          pageSize: innerPageSize.value
        };
        if (isTriggerChange !== false) (_props2$onChange = props2.onChange) === null || _props2$onChange === void 0 ? void 0 : _props2$onChange.call(props2, pageInfo);
        setInnerCurrent(current2, pageInfo);
      }
    };
    var handlePageChange = function handlePageChange(type) {
      var pageChangeMap = {
        prevPage: function prevPage() {
          return toPage(innerCurrent.value - 1);
        },
        nextPage: function nextPage() {
          return toPage(innerCurrent.value + 1);
        },
        prevMorePage: function prevMorePage() {
          return toPage(innerCurrent.value - props2.foldedMaxPageBtn);
        },
        nextMorePage: function nextMorePage() {
          return toPage(innerCurrent.value + props2.foldedMaxPageBtn);
        }
      };
      pageChangeMap[type]();
    };
    var onSelectorChange = function onSelectorChange(e) {
      var _props2$onChange2;
      if (props2.disabled) return;
      var pageSize2 = parseInt(e, 10);
      var pageCount2 = 1;
      if (pageSize2 > 0) pageCount2 = Math.ceil(props2.total / pageSize2);
      var isIndexChange = false;
      if (innerCurrent.value > pageCount2) isIndexChange = true;
      var pageInfo = {
        current: isIndexChange ? pageCount2 : innerCurrent.value,
        previous: innerCurrent.value,
        pageSize: pageSize2
      };
      (_props2$onChange2 = props2.onChange) === null || _props2$onChange2 === void 0 ? void 0 : _props2$onChange2.call(props2, pageInfo);
      setInnerPageSize(pageSize2, pageInfo);
      if (isIndexChange) toPage(pageCount2, false);
    };
    var onJumperChange = function onJumperChange(val) {
      var currentIndex = Math.trunc(+val);
      if (_isNaN(currentIndex)) return;
      jumpIndex.value = currentIndex;
      toPage(currentIndex);
    };
    return function () {
      var _slot;
      var total = props2.total,
        pageSizeOptions = props2.pageSizeOptions,
        size = props2.size,
        disabled = props2.disabled,
        showPageSize = props2.showPageSize;
      if (pageCount.value < 1) return null;
      var Jumper = createVNode("div", {
        "class": CLASS_MAP.jumperClass.value
      }, [t(globalConfig.value.jumpTo), createVNode(InputAdornment, {
        "append": "/ ".concat(pageCount.value, " ").concat(t(globalConfig.value.page))
      }, {
        "default": function _default() {
          return [createVNode(InputNumber, {
            "class": CLASS_MAP.jumperInputClass.value,
            "modelValue": jumpIndex.value,
            "onUpdate:modelValue": function onUpdateModelValue($event) {
              return jumpIndex.value = $event;
            },
            "onBlur": onJumperChange,
            "onEnter": onJumperChange,
            "max": pageCount.value,
            "min": min,
            "size": size,
            "disabled": disabled,
            "theme": "normal",
            "placeholder": ""
          }, null)];
        }
      })]);
      return createVNode("div", {
        "class": CLASS_MAP.paginationClass.value
      }, [renderTNodeJSX("totalContent", createVNode("div", {
        "class": CLASS_MAP.totalClass.value
      }, [t(globalConfig.value.total, {
        total: total
      })])), showPageSize && pageSizeOptions.length > 0 && createVNode(Select, mergeProps({
        "size": size,
        "value": innerPageSize,
        "disabled": disabled,
        "class": CLASS_MAP.sizerClass.value,
        "autoWidth": true,
        "onChange": onSelectorChange
      }, props2.selectProps), _isSlot(_slot = sizeOptions.value.map(function (item, index) {
        return createVNode(Option, {
          "value": item.value,
          "label": item.label,
          "key": index
        }, null);
      })) ? _slot : {
        "default": function _default() {
          return [_slot];
        }
      }), props2.showFirstAndLastPageBtn ? createVNode("div", mergeProps({
        "class": CLASS_MAP.preBtnClass.value,
        "onClick": function onClick() {
          return toPage(1);
        }
      }, {
        disabled: props2.disabled || props2.current === min
      }), [createVNode(PageFirstIcon$1, null, null)]) : null, props2.showPreviousAndNextBtn ? createVNode("div", mergeProps({
        "class": CLASS_MAP.preBtnClass.value,
        "onClick": function onClick() {
          return handlePageChange("prevPage");
        }
      }, {
        disabled: disabled || innerCurrent.value === min
      }), [createVNode(ChevronLeftIcon$1, null, null)]) : null, props2.showPageNumber && props2.theme === "default" ? createVNode("ul", {
        "class": CLASS_MAP.btnWrapClass.value
      }, [isFolded.value && isMidEllipsis.value && createVNode("li", {
        "class": CLASS_MAP.getButtonClass(1),
        "onClick": function onClick() {
          return toPage(min);
        }
      }, [min]), isFolded.value && isPrevMoreShow.value && isMidEllipsis.value ? createVNode("li", {
        "class": CLASS_MAP.btnMoreClass.value,
        "onClick": function onClick() {
          return handlePageChange("prevMorePage");
        },
        "onMouseover": function onMouseover() {
          return prevMore.value = true;
        },
        "onMouseout": function onMouseout() {
          return prevMore.value = false;
        }
      }, [prevMore.value ? createVNode(ChevronLeftDoubleIcon$1, null, null) : createVNode(EllipsisIcon$1, null, null)]) : null, pages.value.map(function (i) {
        return createVNode("li", {
          "class": CLASS_MAP.getButtonClass(i),
          "key": i,
          "onClick": function onClick() {
            return toPage(i);
          }
        }, [i]);
      }), isFolded.value && isNextMoreShow.value && isMidEllipsis.value ? createVNode("li", {
        "class": CLASS_MAP.btnMoreClass.value,
        "onClick": function onClick() {
          return handlePageChange("nextMorePage");
        },
        "onMouseover": function onMouseover() {
          return nextMore.value = true;
        },
        "onMouseout": function onMouseout() {
          return nextMore.value = false;
        }
      }, [nextMore.value ? createVNode(ChevronRightDoubleIcon$1, null, null) : createVNode(EllipsisIcon$1, null, null)]) : null, isFolded.value && isMidEllipsis.value ? createVNode("li", {
        "class": CLASS_MAP.getButtonClass(pageCount.value),
        "onClick": function onClick() {
          return toPage(pageCount.value);
        }
      }, [pageCount.value]) : null]) : null, props2.theme === "simple" && Jumper, props2.showPreviousAndNextBtn ? createVNode("div", mergeProps({
        "class": CLASS_MAP.nextBtnClass.value,
        "onClick": function onClick() {
          return handlePageChange("nextPage");
        }
      }, {
        disabled: disabled || innerCurrent.value === pageCount.value
      }), [createVNode(ChevronRightIcon$1, null, null)]) : null, props2.showFirstAndLastPageBtn ? createVNode("div", mergeProps({
        "class": CLASS_MAP.nextBtnClass.value,
        "onClick": function onClick() {
          return toPage(pageCount.value);
        }
      }, {
        disabled: disabled || innerCurrent.value === pageCount.value
      }), [createVNode(PageLastIcon$1, null, null)]) : null, props2.theme === "default" && props2.showJumper && Jumper]);
    };
  }
});

export { _Pagination as default };
//# sourceMappingURL=pagination.mjs.map
