'use strict';

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

var vue = require('vue');
var elementPlus = require('element-plus');
var table = require('../../../../../constants/table.js');
var general = require('../../../../../utils/src/general.js');
var tablePagination = require('./tablePagination.js');

var _sfc_main = /* @__PURE__ */ vue.defineComponent({
  ...{
    name: "GmTablePagination"
  },
  __name: "TablePagination",
  props: tablePagination.tablePaginationProps,
  emits: ["update:page", "update:limit", "pagination"],
  setup(__props, { emit: __emit }) {
    const tableCtx = vue.inject(table.TableCtxKey, {});
    const canUseSize = general.isVersionGreaterOrEqual(elementPlus.version, "2.7.6");
    const props = __props;
    const emit = __emit;
    const currentPage = vue.computed({
      get() {
        return props.page;
      },
      set(val) {
        emit("update:page", val);
      }
    });
    const pageSize = vue.computed({
      get() {
        return props.limit;
      },
      set(val) {
        emit("update:limit", val);
      }
    });
    function handleSizeChange(val) {
      if (currentPage.value * val > props.total) {
        currentPage.value = 1;
      }
      emit("pagination", { page: currentPage.value, limit: val });
      tableCtx?.tableRef?.value?.scrollTo({ top: 0, behavior: "smooth" });
      tableCtx.tableV2Ref?.value?.scrollTo({ scrollLeft: 0, scrollTop: 0 });
    }
    function handleCurrentChange(val) {
      emit("pagination", { page: val, limit: pageSize.value });
      tableCtx?.tableRef?.value?.scrollTo({ top: 0, behavior: "smooth" });
      tableCtx.tableV2Ref?.value?.scrollTo({ scrollLeft: 0, scrollTop: 0 });
    }
    return (_ctx, _cache) => {
      const _component_gm_pagination = vue.resolveComponent("gm-pagination");
      return vue.openBlock(), vue.createElementBlock(
        "div",
        {
          class: vue.normalizeClass([{ hidden: _ctx.hidden }, "pagination-container gm-flex gm-justify-end"])
        },
        [
          vue.createVNode(_component_gm_pagination, {
            "current-page": currentPage.value,
            "onUpdate:currentPage": _cache[0] || (_cache[0] = ($event) => currentPage.value = $event),
            "page-size": pageSize.value,
            "onUpdate:pageSize": _cache[1] || (_cache[1] = ($event) => pageSize.value = $event),
            background: _ctx.background,
            layout: _ctx.layout,
            "page-sizes": _ctx.pageSizes,
            "pager-count": _ctx.pagerCount,
            total: _ctx.total,
            small: vue.unref(canUseSize) ? void 0 : _ctx.small,
            size: vue.unref(canUseSize) ? _ctx.size : void 0,
            onSizeChange: handleSizeChange,
            onCurrentChange: handleCurrentChange
          }, null, 8, ["current-page", "page-size", "background", "layout", "page-sizes", "pager-count", "total", "small", "size"])
        ],
        2
        /* CLASS */
      );
    };
  }
});

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