import { defineComponent, useAttrs, ref, computed, resolveComponent, createElementBlock, openBlock, normalizeClass, unref, createVNode, createCommentVNode, mergeProps, createTextVNode } from 'vue';
import '../../../../utils/index.mjs';
import '../config/index.mjs';
import { createNamespace } from '../../../../utils/create-namespace.mjs';
import { tablePaginationProps } from '../config/pagination.mjs';

"use strict";
var _sfc_main = /* @__PURE__ */ defineComponent({
  ...{ name: "LlPagination" },
  __name: "pagination",
  props: tablePaginationProps,
  setup(__props) {
    const props = __props;
    const attrs = useAttrs();
    const bem = createNamespace("table");
    const current = ref(void 0);
    const max = computed(() => Math.ceil(props.total / props.pageSize));
    const localPageSize = 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 = resolveComponent("a-pagination");
      const _component_a_input_number = resolveComponent("a-input-number");
      return openBlock(), createElementBlock(
        "div",
        {
          class: normalizeClass([
            unref(bem).e("pagination-box"),
            props.alignment === "left" && unref(bem).m("left"),
            props.alignment === "center" && unref(bem).m("center"),
            props.alignment === "right" && unref(bem).m("right")
          ])
        },
        [
          createVNode(_component_a_pagination, mergeProps(unref(attrs), {
            size: _ctx.size,
            class: `${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 ? (openBlock(), createElementBlock(
            "div",
            {
              key: 0,
              class: normalizeClass([unref(bem).e("pagination-quick-jump")])
            },
            [
              _cache[1] || (_cache[1] = createTextVNode(
                " \u8DF3\u81F3 ",
                -1
                /* CACHED */
              )),
              createVNode(_component_a_input_number, {
                value: current.value,
                "onUpdate:value": _cache[0] || (_cache[0] = ($event) => current.value = $event),
                disabled: max.value <= 1,
                class: normalizeClass([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] = createTextVNode(
                " \u9875 ",
                -1
                /* CACHED */
              ))
            ],
            2
            /* CLASS */
          )) : createCommentVNode("v-if", true),
          createCommentVNode(' :show-total="(total: number) => `\u5171 ${total} \u6761`" '),
          createCommentVNode(' :show-total="(total, range) => showTotal?.(total, range)" '),
          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 */
      );
    };
  }
});

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