var u = Object.defineProperty, d = Object.defineProperties;
var f = Object.getOwnPropertyDescriptors;
var h = Object.getOwnPropertySymbols;
var S = Object.prototype.hasOwnProperty, w = Object.prototype.propertyIsEnumerable;
var c = (e, a, t) => a in e ? u(e, a, { enumerable: !0, configurable: !0, writable: !0, value: t }) : e[a] = t, l = (e, a) => {
  for (var t in a || (a = {}))
    S.call(a, t) && c(e, t, a[t]);
  if (h)
    for (var t of h(a))
      w.call(a, t) && c(e, t, a[t]);
  return e;
}, n = (e, a) => d(e, f(a));
import { h as g } from "vue";
import { t as p, T as y } from "./Table.js";
import { a_ as m } from "./index2.js";
const O = {
  data() {
    return {
      needTotalList: [],
      selectedRows: [],
      selectedRowKeys: [],
      localLoading: !1,
      localDataSource: [],
      localPagination: Object.assign({}, this.pagination),
      pageSizeOptions: ["10", "20", "50", "100", "500"]
    };
  },
  props: Object.assign({}, p(), {
    rowKey: {
      type: [String, Function],
      default: "key"
    },
    data: {
      type: Function,
      required: !0
    },
    loading: {
      type: Boolean,
      default: !1
    },
    pageNo: {
      type: Number,
      default: 1
    },
    pageSize: {
      type: Number,
      default: 10
    },
    showSizeChanger: {
      type: Boolean,
      default: !0
    },
    size: {
      type: String,
      default: "default"
    },
    /**
     * alert: {
     *   show: true,
     *   clear: Function
     * }
     */
    alert: {
      type: [Object, Boolean],
      default: null
    },
    rowSelection: {
      type: Object,
      default: null
    },
    /** @Deprecated */
    showAlertInfo: {
      type: Boolean,
      default: !1
    },
    showPagination: {
      type: [String, Boolean],
      default: "auto"
    },
    /**
     * enable page URI mode
     *
     * e.g:
     * /users/1
     * /users/2
     * /users/3?queryParam=test
     * ...
     */
    pageURI: {
      type: Boolean,
      default: !1
    }
  }),
  watch: {
    "localPagination.current"(e) {
      this.pageURI && this.router.push(n(l({}, this.$route), {
        name: this.$route.name,
        params: Object.assign({}, this.$route.params, {
          pageNo: e
        })
      }));
    },
    pageNo(e) {
      Object.assign(this.localPagination, {
        current: e
      });
    },
    pageSize(e) {
      Object.assign(this.localPagination, {
        pageSize: e
      });
    },
    showSizeChanger(e) {
      Object.assign(this.localPagination, {
        showSizeChanger: e
      });
    }
  },
  created() {
    const { pageNo: e } = this.$route.params, a = this.pageURI && e && parseInt(e) || this.pageNo;
    this.localPagination = ["auto", !0].includes(this.showPagination) && Object.assign({}, this.localPagination, {
      current: a,
      pageSize: this.pageSize,
      pageSizeOptions: this.pageSizeOptions,
      showSizeChanger: this.showSizeChanger,
      showQuickJumper: !0,
      showTotal: (t) => `共${t}条`
    }) || !1, this.needTotalList = this.initTotalList(this.columns), this.loadData();
  },
  methods: {
    getTableHeight() {
      return "500px";
    },
    /**
     * 表格重新加载方法
     * 如果参数为 true, 则强制刷新到第一页
     * @param Boolean bool
     */
    refresh(e = !1) {
      e && (this.localPagination = Object.assign(
        {},
        {
          current: 1,
          pageSize: this.pageSize
        }
      )), this.loadData();
    },
    /**
     * 加载数据方法
     * @param {Object} pagination 分页选项器
     * @param {Object} filters 过滤条件
     * @param {Object} sorter 排序条件
     */
    loadData(e, a, t) {
      const i = Object.assign(
        {
          pageNo: e && e.current || this.showPagination && this.localPagination.current || this.pageNo,
          pageSize: e && e.pageSize || this.showPagination && this.localPagination.pageSize || this.pageSize
        },
        t && t.field && {
          sortField: t.field
        } || {},
        t && t.order && {
          sortOrder: t.order
        } || {},
        l({}, a)
      ), s = this.data(i);
      (typeof s == "object" || typeof s == "function") && typeof s.then == "function" && (this.localLoading = !0, s.then((o) => {
        if (this.localPagination = this.showPagination && Object.assign({}, this.localPagination, {
          current: o.pageNo,
          // 返回结果中的当前分页数
          total: o.total,
          // 返回结果中的总记录数
          showSizeChanger: this.showSizeChanger,
          pageSize: e && e.pageSize || this.localPagination.pageSize
        }) || !1, o.list.length === 0 && this.showPagination && this.localPagination.current > 1) {
          this.localPagination.current--, this.loadData();
          return;
        }
        this.localDataSource = o.list, this.localLoading = !1;
      }));
    },
    initTotalList(e) {
      const a = [];
      return e && e instanceof Array && e.forEach((t) => {
        t.needTotal && a.push(n(l({}, t), {
          total: 0
        }));
      }), a;
    },
    /**
     * 用于更新已选中的列表数据 total 统计
     * @param selectedRowKeys
     * @param selectedRows
     */
    updateSelect(e, a) {
      this.selectedRows = a, this.selectedRowKeys = e;
      const t = this.needTotalList;
      this.needTotalList = t.map((i) => n(l({}, i), {
        total: a.reduce((s, o) => {
          const r = s + parseInt(m(o, i.dataIndex));
          return isNaN(r) ? 0 : r;
        }, 0)
      }));
    },
    /**
     * 清空 table 已选中项
     */
    clearSelected() {
      this.rowSelection && (this.rowSelection.onChange([], []), this.updateSelect([], []));
    },
    /**
     * 处理交给 table 使用者去处理 clear 事件时，内部选中统计同时调用
     * @param callback
     * @returns {*}
     */
    renderClear(e) {
      return this.selectedRowKeys.length <= 0 ? null : /* @__PURE__ */ React.createElement(
        "a",
        {
          style: "margin-left: 24px",
          onClick: () => {
            e(), this.clearSelected();
          }
        },
        "清空"
      );
    },
    renderAlert() {
      const e = this.needTotalList.map((t) => /* @__PURE__ */ React.createElement("span", { style: "margin-right: 12px" }, t.title, "总计", " ", /* @__PURE__ */ React.createElement("a", { style: "font-weight: 600" }, t.customRender ? t.customRender(t.total) : t.total))), a = typeof this.alert.clear == "boolean" && this.alert.clear ? this.renderClear(this.clearSelected) : this.alert !== null && typeof this.alert.clear == "function" ? this.renderClear(this.alert.clear) : null;
      return /* @__PURE__ */ React.createElement("a-alert", { showIcon: !0, style: "margin-bottom: 16px" }, /* @__PURE__ */ React.createElement("template", { "v-slot:message": !0 }, /* @__PURE__ */ React.createElement("span", { style: "margin-right: 12px" }, "已选择: ", /* @__PURE__ */ React.createElement("a", { style: "font-weight: 600" }, this.selectedRows.length)), e, a));
    }
  },
  render() {
    const e = {}, a = Object.keys(this.$data), t = typeof this.alert == "object" && this.alert !== null && this.alert.show && typeof this.rowSelection.selectedRowKeys != "undefined" || this.alert;
    return Object.keys(p()).forEach((i) => {
      const s = `local${i.substring(0, 1).toUpperCase()}${i.substring(1)}`;
      if (a.includes(s))
        return e[i] = this[s], e[i];
      if (i === "rowSelection") {
        if (t && this.rowSelection)
          return e[i] = n(l({}, this.rowSelection), {
            selectedRows: this.selectedRows,
            selectedRowKeys: this.selectedRowKeys,
            onChange: (o, r) => {
              this.updateSelect(o, r), typeof this[i].onChange != "undefined" && this[i].onChange(o, r);
            }
          }), e[i];
        if (!this.rowSelection)
          return e[i] = null, e[i];
      } else i === "scroll" && (this.scroll || (e[i] = { y: getTableHeight() }));
      return this[i] && (e[i] = this[i]), e[i];
    }), g("div", { class: "table-wrapper" }, t ? this.renderAlert() : null, [
      g(
        y,
        n(l({}, e), {
          onChange: this.loadData,
          onExpand: (i, s) => {
            this.$emit("expand", i, s);
          }
        }),
        l({}, this.$slots)
      )
    ]);
  }
};
export {
  O as S
};
