'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var vue = require('vue');
require('../../../../utils/index.js');
require('../config/index.js');
var createNamespace = require('../../../../utils/create-namespace.js');
var pagination = require('../config/pagination.js');

"use strict";
var _sfc_main = /* @__PURE__ */ vue.defineComponent({
  ...{ name: "LlPagination" },
  __name: "pagination",
  props: pagination.tablePaginationProps,
  setup(__props) {
    const props = __props;
    const attrs = vue.useAttrs();
    const bem = createNamespace.createNamespace("table");
    const current = vue.ref(void 0);
    const max = vue.computed(() => Math.ceil(props.total / props.pageSize));
    const localPageSize = vue.computed({
      get() {
        return props.pageSize;
      },
      set(newVal) {
        if (props.onChange) {
          props.onChange(props.current || 1, newVal);
        }
      }
    });
    const handlePageChange = (page, pageSize) => props.onChange && props.onChange(page, pageSize);
    const handleNumberChange = () => {
      if (current.value === void 0) return;
      if (current.value < 1) {
        current.value = 1;
      } else if (current.value > max.value) {
        current.value = max.value;
      }
      handlePageChange(current.value, props.pageSize);
      current.value = void 0;
    };
    return (_ctx, _cache) => {
      const _component_a_pagination = vue.resolveComponent("a-pagination");
      const _component_a_input_number = vue.resolveComponent("a-input-number");
      return vue.openBlock(), vue.createElementBlock(
        "div",
        {
          class: vue.normalizeClass([
            vue.unref(bem).e("pagination-box"),
            props.alignment === "left" && vue.unref(bem).m("left"),
            props.alignment === "center" && vue.unref(bem).m("center"),
            props.alignment === "right" && vue.unref(bem).m("right")
          ])
        },
        [
          vue.createVNode(_component_a_pagination, vue.mergeProps(vue.unref(attrs), {
            size: _ctx.size,
            class: `${vue.unref(bem).e("pagination")}`,
            current: props.current,
            "page-size": localPageSize.value,
            total: props.total,
            "show-size-changer": !_ctx.simple,
            "show-total": (total) => `\u5171 ${total} \u6761`,
            onChange: handlePageChange
          }), null, 16, ["size", "class", "current", "page-size", "total", "show-size-changer", "show-total"]),
          !props.simple ? (vue.openBlock(), vue.createElementBlock(
            "div",
            {
              key: 0,
              class: vue.normalizeClass([vue.unref(bem).e("pagination-quick-jump")])
            },
            [
              _cache[1] || (_cache[1] = vue.createTextVNode(
                " \u8DF3\u81F3 ",
                -1
                /* CACHED */
              )),
              vue.createVNode(_component_a_input_number, {
                value: current.value,
                "onUpdate:value": _cache[0] || (_cache[0] = ($event) => current.value = $event),
                disabled: max.value <= 1,
                class: vue.normalizeClass([vue.unref(bem).e("pagination-input")]),
                size: _ctx.size,
                precision: 0,
                controls: false,
                onBlur: handleNumberChange,
                onPressEnter: handleNumberChange
              }, null, 8, ["value", "disabled", "class", "size"]),
              _cache[2] || (_cache[2] = vue.createTextVNode(
                " \u9875 ",
                -1
                /* CACHED */
              ))
            ],
            2
            /* CLASS */
          )) : vue.createCommentVNode("v-if", true),
          vue.createCommentVNode(' :show-total="(total: number) => `\u5171 ${total} \u6761`" '),
          vue.createCommentVNode(' :show-total="(total, range) => showTotal?.(total, range)" '),
          vue.createCommentVNode(' <a-pagination\n      v-bind="attrs"\n      :class="`${bem.e(\'pagination\')}`"\n      :current="props.current"\n      :page-size="props.pageSize"\n      :total="props.total"\n      show-size-changer\n      show-quick-jumper\n      :show-total="(total, range) => showTotal?.(total, range)"\n      @change="handlePageChange"\n    /> ')
        ],
        2
        /* CLASS */
      );
    };
  }
});

exports.default = _sfc_main;
//# sourceMappingURL=pagination.vue2.js.map
