import { defineComponent as U, reactive as J, computed as F, ref as K, onMounted as W, resolveComponent as j, openBlock as u, createElementBlock as b, createElementVNode as _, createBlock as p, unref as g, mergeProps as h, withCtx as f, renderSlot as C, createVNode as v, createTextVNode as Q, createCommentVNode as P, Fragment as O, renderList as X, toDisplayString as Y, resolveDynamicComponent as A, nextTick as Z } from "vue";
import { Button as k, Table as ee } from "ant-design-vue";
import { m as N, e as te, _ as oe } from "./index.14fbe0a4.js";
function ne(m) {
  const d = N({
    size: "small",
    pagination: {
      pageSizeOptions: ["10", "20", "30", "50", "100", "200", "500"],
      "show-total": (c) => `\u603B\u6570\u636E ${c} \u6761`,
      "show-quick-jumper": !0
    }
  }, m), { columns: i = [] } = d, t = i.filter((c) => {
    if (!c.hide)
      return !0;
    if (typeof c.hide == "boolean")
      return !c.hide;
    try {
      return c.hide && !c.hide();
    } catch {
      return !0;
    }
  });
  return t.find((c) => c.fixed) && !d.scroll && (d.scroll = { x: 800 }), d.columns = t, d;
}
function ae(m) {
  return N({
    queryForm: !0,
    actionProps: {
      colProps: {
        flex: 1
      }
    },
    formProps: {
      layout: "horizontal",
      rowAttr: {
        gutter: 10
      },
      baseColAttr: {
        span: 6
      },
      columns: [{
        field: "keywords",
        label: "\u5173\u952E\u5B57",
        component: "a-input",
        componentProps: {}
      }]
    }
  }, m);
}
const re = { class: "search-box" }, le = { class: "actions-box" }, se = {
  key: 0,
  class: "middle-box"
}, ce = { class: "table-content" }, ie = { class: "column-actions" }, ue = /* @__PURE__ */ U({
  __name: "Table",
  props: {
    api: {
      type: [Function],
      default: () => {
      }
    },
    extraParams: {
      type: [Object],
      default: () => ({})
    },
    autoGet: {
      type: [Boolean],
      default: !0
    },
    tableProps: {
      type: [Object],
      default: () => ({})
    },
    formProps: {
      type: [Object],
      default: () => ({})
    }
  },
  emits: ["handle-action", "register", "get-params"],
  setup(m, { emit: x }) {
    const d = x, i = m, t = J({
      searchQuery: {
        pageIndex: 1,
        pageSize: 30
      },
      loading: !1,
      tableData: {
        records: [],
        total: 0
      }
    }), D = F(() => {
      const { dataSource: e } = i.tableProps;
      if (e)
        return e || [];
      const { records: o } = t.tableData;
      return o || (Array.isArray(t.tableData) ? t.tableData : []);
    }), c = F(() => ae(i.formProps)), V = F(() => {
      const e = ne(i.tableProps);
      return Object.assign(e.pagination, {
        current: t.searchQuery.pageIndex,
        pageSize: t.searchQuery.pageSize,
        total: t.tableData.total || D.value.length || 0,
        defaultPageSize: t.searchQuery.pageSize
      }), e;
    }), B = K(null);
    function w() {
      const e = B.value;
      I(e.children), H(e);
    }
    function H(e, o = "table-content") {
      let n = 0;
      for (let a = 0; a < e.children.length; a++) {
        const r = e.children[a];
        r.className !== o && (n += r.offsetHeight);
      }
      return e.offsetHeight - n;
    }
    function I(e, o = "table-content") {
      for (let n = 0; n < e.length; n++) {
        const s = e[n];
        if (s.className === o)
          return s;
      }
      return {};
    }
    function T() {
      const e = $();
      d("get-params", e), t.loading = !0, i.api && i.api(e).then((o) => {
        t.tableData = o.data;
      }).finally(() => {
        t.loading = !1;
      });
    }
    function $() {
      const { columns: e = [] } = i.formProps.formProps || {}, o = {};
      return e.forEach((n) => {
        const { field: s, timeRangeFieldNames: a } = n;
        if (!s || !a)
          return;
        const { startTime: r, endTime: l } = a;
        if (t.searchQuery[s])
          try {
            t.searchQuery[r] = t.searchQuery[s][0], t.searchQuery[l] = t.searchQuery[s][1];
          } catch {
            console.log("\u89E3\u6790\u65F6\u95F4\u53C2\u6570\u5931\u8D25");
          }
      }), { ...i.extraParams, ...t.searchQuery, ...o };
    }
    function R() {
      t.searchQuery.pageIndex = 1, y();
    }
    function y() {
      T();
    }
    function q(e, o, n, s) {
      t.searchQuery.pageIndex = e.current, t.searchQuery.pageSize = e.pageSize, y();
    }
    function G(e) {
      const { resetFormData: o } = e;
      o(), Z(() => {
        y();
      });
    }
    function L(e, o) {
      const { hide: n = !1 } = e;
      if (typeof n == "boolean")
        return !n;
      try {
        return !n(o);
      } catch {
        return !0;
      }
    }
    function E({ type: e, item: o, record: n }) {
      e === "confirm" && o.popconfirm.confirm && o.popconfirm.confirm(n), e === "cancle" && o.popconfirm.cancle && o.popconfirm.cancle(n);
    }
    function z(e, o) {
      const { onClick: n } = e;
      d("handle-action", { item: e, record: o });
      try {
        n && n(o);
      } catch (s) {
        console.log("\u6267\u884C\u4E8B\u4EF6\u5931\u8D25", s);
      }
    }
    return d("register", { reload: R, getParams: $ }), W(() => {
      w(), i.autoGet && T();
    }), (e, o) => {
      const n = j("a-popconfirm"), s = j("a-tooltip");
      return u(), b("div", {
        class: "config-table table-box",
        ref_key: "tableRef",
        ref: B
      }, [
        _("div", re, [
          c.value.queryForm ? (u(), p(g(te), h({
            key: 0,
            modelValue: t.searchQuery,
            "onUpdate:modelValue": o[0] || (o[0] = (a) => t.searchQuery = a)
          }, c.value), {
            actions: f((a) => [
              _("div", le, [
                C(e.$slots, "formLeft", {
                  actions: { ...a }
                }, void 0, !0),
                v(g(k), {
                  type: "primary",
                  loading: t.loading,
                  onClick: y
                }, {
                  default: f(() => [
                    Q("\u67E5\u8BE2")
                  ]),
                  _: 1
                }, 8, ["loading"]),
                v(g(k), {
                  loading: t.loading,
                  onClick: (r) => G(a)
                }, {
                  default: f(() => [
                    Q("\u91CD\u7F6E")
                  ]),
                  _: 2
                }, 1032, ["loading", "onClick"]),
                C(e.$slots, "formRight", {
                  actions: { ...a }
                }, void 0, !0)
              ])
            ]),
            _: 3
          }, 16, ["modelValue"])) : P("", !0)
        ]),
        e.$slots.middle ? (u(), b("div", se, [
          C(e.$slots, "middle", {}, void 0, !0)
        ])) : P("", !0),
        _("div", ce, [
          v(g(ee), h(V.value, {
            loading: t.loading,
            dataSource: D.value,
            total: t.tableData.total,
            onChange: q
          }), {
            bodyCell: f(({ column: a, record: r }) => [
              a.dataIndex === "actions" ? C(e.$slots, "actions", {
                key: 0,
                column: a,
                record: r
              }, () => [
                _("div", ie, [
                  (u(!0), b(O, null, X(a.buttons, (l, M) => (u(), b(O, { key: M }, [
                    L(l, r) ? (u(), p(s, { key: 0 }, {
                      title: f(() => [
                        Q(Y(l.title), 1)
                      ]),
                      default: f(() => [
                        l.popconfirm ? (u(), p(n, h({ key: 0 }, l.popconfirm, {
                          onConfirm: (S) => E({ type: "confirm", item: l, record: r }),
                          onCancel: (S) => E({ type: "cancle", item: l, record: r })
                        }), {
                          default: f(() => [
                            v(g(k), h({
                              shape: "circle",
                              loading: r.loading
                            }, l.props, {
                              onClick: (S) => z(l, r)
                            }), {
                              icon: f(() => [
                                (u(), p(A(l.icon)))
                              ]),
                              _: 2
                            }, 1040, ["loading", "onClick"])
                          ]),
                          _: 2
                        }, 1040, ["onConfirm", "onCancel"])) : (u(), p(g(k), h({
                          key: 1,
                          shape: "circle",
                          loading: r.loading
                        }, l.props, {
                          onClick: (S) => z(l, r)
                        }), {
                          icon: f(() => [
                            (u(), p(A(l.icon)))
                          ]),
                          _: 2
                        }, 1040, ["loading", "onClick"]))
                      ]),
                      _: 2
                    }, 1024)) : P("", !0)
                  ], 64))), 128))
                ])
              ], !0) : P("", !0)
            ]),
            _: 3
          }, 16, ["loading", "dataSource", "total"])
        ])
      ], 512);
    };
  }
});
const de = /* @__PURE__ */ oe(ue, [["__scopeId", "data-v-85c56daa"]]), me = de;
export {
  me as C
};
