import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
var _excluded = ["size", "itemRender", "buildOptionText"];
import { createVNode as _createVNode, createTextVNode as _createTextVNode } from "vue";
import { computed, toRef, defineComponent } from 'vue';
import LeftOutlined from '@ant-design/icons-vue/LeftOutlined';
import RightOutlined from '@ant-design/icons-vue/RightOutlined';
import DoubleLeftOutlined from '@ant-design/icons-vue/DoubleLeftOutlined';
import DoubleRightOutlined from '@ant-design/icons-vue/DoubleRightOutlined';
import { tuple } from '../_util/type';
import PropTypes, { withUndefined } from '../_util/vue-types';
import VcSelect from '../select';
import MiniSelect from './MiniSelect';
import { useLocaleReceiver } from '../locale-provider/LocaleReceiver';
import VcPagination from '../vc-pagination';
import enUS from '../vc-pagination/locale/en_US';
import classNames from '../_util/classNames';
import useConfigInject from '../_util/hooks/useConfigInject';
export var paginationProps = function paginationProps() {
  return {
    total: PropTypes.number,
    defaultCurrent: PropTypes.number,
    disabled: PropTypes.looseBool,
    current: PropTypes.number,
    defaultPageSize: PropTypes.number,
    pageSize: PropTypes.number,
    hideOnSinglePage: PropTypes.looseBool,
    showSizeChanger: PropTypes.looseBool,
    pageSizeOptions: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.number, PropTypes.string])),
    buildOptionText: PropTypes.func,
    showSizeChange: PropTypes.func,
    showQuickJumper: withUndefined(PropTypes.oneOfType([PropTypes.looseBool, PropTypes.object])),
    showTotal: PropTypes.any,
    size: PropTypes.string,
    simple: PropTypes.looseBool,
    locale: PropTypes.object,
    prefixCls: PropTypes.string,
    selectPrefixCls: PropTypes.string,
    itemRender: PropTypes.func,
    role: PropTypes.string,
    showLessItems: PropTypes.looseBool,
    onChange: PropTypes.func,
    onShowSizeChange: PropTypes.func,
    'onUpdate:current': PropTypes.func,
    'onUpdate:pageSize': PropTypes.func
  };
};
export var paginationConfig = function paginationConfig() {
  return _objectSpread(_objectSpread({}, paginationProps()), {}, {
    position: PropTypes.oneOf(tuple('top', 'bottom', 'both'))
  });
};
export default defineComponent({
  name: 'APagination',
  inheritAttrs: false,
  props: paginationProps(),
  emits: ['change', 'showSizeChange', 'update:current', 'update:pageSize'],
  setup: function setup(props, _ref) {
    var slots = _ref.slots,
        attrs = _ref.attrs;

    var _useConfigInject = useConfigInject('pagination', props),
        prefixCls = _useConfigInject.prefixCls,
        configProvider = _useConfigInject.configProvider,
        direction = _useConfigInject.direction;

    var selectPrefixCls = computed(function () {
      return configProvider.getPrefixCls('select', props.selectPrefixCls);
    });

    var _useLocaleReceiver = useLocaleReceiver('Pagination', enUS, toRef(props, 'locale')),
        _useLocaleReceiver2 = _slicedToArray(_useLocaleReceiver, 1),
        locale = _useLocaleReceiver2[0];

    var getIconsProps = function getIconsProps(pre) {
      var ellipsis = _createVNode("span", {
        "class": "".concat(pre, "-item-ellipsis")
      }, [_createTextVNode("\u2022\u2022\u2022")]);

      var prevIcon = _createVNode("button", {
        "class": "".concat(pre, "-item-link"),
        "type": "button",
        "tabindex": -1
      }, [_createVNode(LeftOutlined, null, null)]);

      var nextIcon = _createVNode("button", {
        "class": "".concat(pre, "-item-link"),
        "type": "button",
        "tabindex": -1
      }, [_createVNode(RightOutlined, null, null)]);

      var jumpPrevIcon = _createVNode("a", {
        "class": "".concat(pre, "-item-link")
      }, [_createVNode("div", {
        "class": "".concat(pre, "-item-container")
      }, [_createVNode(DoubleLeftOutlined, {
        "class": "".concat(pre, "-item-link-icon")
      }, null), ellipsis])]);

      var jumpNextIcon = _createVNode("a", {
        "class": "".concat(pre, "-item-link")
      }, [_createVNode("div", {
        "class": "".concat(pre, "-item-container")
      }, [_createVNode(DoubleRightOutlined, {
        "class": "".concat(pre, "-item-link-icon")
      }, null), ellipsis])]); // change arrows direction in right-to-left direction


      if (direction.value === 'rtl') {
        var _ref2 = [nextIcon, prevIcon];
        prevIcon = _ref2[0];
        nextIcon = _ref2[1];
        var _ref3 = [jumpNextIcon, jumpPrevIcon];
        jumpPrevIcon = _ref3[0];
        jumpNextIcon = _ref3[1];
      }

      return {
        prevIcon: prevIcon,
        nextIcon: nextIcon,
        jumpPrevIcon: jumpPrevIcon,
        jumpNextIcon: jumpNextIcon
      };
    };

    return function () {
      var size = props.size,
          _props$itemRender = props.itemRender,
          itemRender = _props$itemRender === void 0 ? slots.itemRender : _props$itemRender,
          _props$buildOptionTex = props.buildOptionText,
          buildOptionText = _props$buildOptionTex === void 0 ? slots.buildOptionText : _props$buildOptionTex,
          restProps = _objectWithoutProperties(props, _excluded);

      var isSmall = size === 'small';

      var paginationProps = _objectSpread(_objectSpread(_objectSpread(_objectSpread({}, restProps), getIconsProps(prefixCls.value)), {}, {
        prefixCls: prefixCls.value,
        selectPrefixCls: selectPrefixCls.value,
        selectComponentClass: isSmall ? MiniSelect : VcSelect,
        locale: locale.value,
        buildOptionText: buildOptionText
      }, attrs), {}, {
        class: classNames(_defineProperty({
          mini: isSmall
        }, "".concat(prefixCls.value, "-rtl"), direction.value === 'rtl'), attrs.class),
        itemRender: itemRender
      });

      return _createVNode(VcPagination, paginationProps, null);
    };
  }
});