import { defineComponent as je, useSlots as He, ref as f, computed as n, unref as r, toRef as Ue, createVNode as m, Fragment as le, watch as k, openBlock as p, createElementBlock as z, normalizeStyle as L, normalizeClass as g, mergeProps as I, createSlots as ne, withCtx as v, renderList as se, createBlock as ue, resolveDynamicComponent as qe, renderSlot as R, createCommentVNode as de, createElementVNode as K, normalizeProps as Me, guardReactiveProps as Ge } from "vue";
import { Divider as Je, Table as Qe } from "@aplus-frontend/antdv";
import { useToken as Xe } from "@aplus-frontend/antdv/es/theme/internal";
import { isUndefined as b, omit as ie, isBoolean as Ye } from "lodash-unified";
import "../scroll-bar/index.mjs";
import { getValidVNodeList as Ze } from "../utils/slot.mjs";
import { useDevWarning as _e } from "../utils/warning.mjs";
import { ApForm as et } from "../ap-form/index.mjs";
import "../config-provider/index.mjs";
import { getScrollbarSize as tt } from "../utils/index.mjs";
import "./components/paragraph-ellipsis/index.vue.mjs";
import "./components/setting/modal/index.vue2.mjs";
import { noRenderAsFormItemValueList as ce } from "./constants.mjs";
import { useProvideApTable as rt } from "./context.mjs";
import { useStickyScroll as ot } from "./hooks/use-sticky-scroll.mjs";
import at from "./hooks/use-table-content-height.mjs";
import { useTablePaging as lt } from "./hooks/use-table-paging-ng.mjs";
import nt from "./hooks/use-table-row-selection.mjs";
import st from "./style/index.mjs";
import { getColumnOrder as fe, updateFormProps as ut, getFieldProps as dt, getSearchFormItemRenderNode as it, recursionApColumns as me, getTableRenderType as ct, getTableRenderProps as ft, getTableCellRenderNode as mt, getTableTitle as pt, apColumnToColumn as gt, falseToUndefined as bt, objectToString as yt } from "./utils.mjs";
import { useNamespace as St } from "../config-provider/hooks/use-namespace.mjs";
import { useGlobalConfig as ht } from "../config-provider/hooks/use-global-config.mjs";
import { isDef as pe } from "../utils/is.mjs";
import wt from "./components/paragraph-ellipsis/index.vue2.mjs";
import vt from "./components/setting/modal/index.vue.mjs";
import Rt from "../scroll-bar/index.vue.mjs";
const Xt = /* @__PURE__ */ je({
  name: "ApTable",
  __name: "ap-table",
  props: {
    dropdownPrefixCls: {},
    loading: {
      type: [Boolean, Object],
      default: void 0
    },
    bordered: {
      type: Boolean,
      default: !1
    },
    locale: {},
    onChange: {},
    onResizeColumn: {},
    getPopupContainer: {},
    scroll: {},
    sortDirections: {
      default: () => ["ascend", "descend"]
    },
    showSorterTooltip: {
      type: [Boolean, Object],
      default: !1
    },
    prefixCls: {},
    rowKey: {
      type: [String, Function],
      default: "key"
    },
    tableLayout: {},
    rowClassName: {},
    title: {},
    footer: {},
    id: {},
    showHeader: {
      type: Boolean,
      default: !0
    },
    components: {},
    customRow: {},
    customHeaderRow: {},
    direction: {},
    expandFixed: {
      type: [String, Boolean],
      default: !1
    },
    expandColumnWidth: {},
    expandedRowKeys: {},
    defaultExpandedRowKeys: {},
    expandedRowRender: {},
    expandRowByClick: {
      type: Boolean,
      default: !1
    },
    expandIcon: {},
    onExpand: {},
    onExpandedRowsChange: {},
    defaultExpandAllRows: {
      type: Boolean,
      default: !1
    },
    indentSize: {
      default: 15
    },
    expandIconColumnIndex: {},
    showExpandColumn: {
      type: Boolean,
      default: !0
    },
    expandedRowClassName: {},
    childrenColumnName: {
      default: "children"
    },
    rowExpandable: {},
    sticky: {
      type: [Boolean, Object]
    },
    transformCellText: {},
    rowHoverable: {
      type: Boolean
    },
    columns: {},
    rowSelection: {
      type: [Boolean, Object]
    },
    card: {
      type: Boolean,
      default: !1
    },
    params: {},
    searchFormRender: {},
    request: {},
    onLoad: {},
    defaultData: {},
    dataSource: {},
    onLoadingChange: {},
    searchForm: {
      type: [Boolean, Object],
      default: void 0
    },
    beforeSearchSubmit: {},
    pagination: {
      type: [Boolean, Object],
      default: void 0
    },
    searchFormWrapperStyle: {},
    tableWrapperStyle: {},
    manual: {
      type: Boolean,
      default: void 0
    },
    size: {
      default: "small"
    },
    adaptive: {
      type: Boolean,
      default: !1
    },
    columnResizable: {
      type: Boolean,
      default: !1
    },
    settings: {
      default: void 0
    }
  },
  setup(d, {
    expose: ge
  }) {
    const t = d;
    let O = 0;
    const y = He(), [, be] = Xe();
    _e("ApTable")(!1, "breaking", "ApTable has been EOL, Please use AgGrid(https://aplus.aplnk.com/aplus-ui/components/ag-grid/) instead.");
    const {
      e: P,
      b: i,
      be: W,
      m: ye,
      cssVar: Se
    } = St("ap-table"), he = st("ap-table"), D = ht("valueTypeMap"), {
      height: we,
      contentRef: ve
    } = at(), $ = f(), j = f(), {
      isStickyMode: H,
      scrollBarRef: x
    } = ot($), C = f(t.size), s = f([]), U = f([]), q = tt(), N = f(!0), M = n(() => (O++, t.columns?.filter((e) => !e.hideInSearch && e.dataIndex && (e.valueType || e.customRenderFormItem) && !ce.includes(e.valueType))?.sort((e, a) => {
      let o = fe(e.order);
      return fe(a.order) - o;
    })?.map((e) => {
      const a = ut(e, dt(e.fieldProps, {})), o = {
        ...e,
        fieldProps: {
          label: e.title,
          name: e.dataIndex,
          // tips: 在表格中的查询表单项默认是带边框的
          bordered: !0,
          ...a || {},
          _signal: O
        },
        renderNode: void 0
      };
      return o.renderNode = it(o, r(D)), o;
    }) || [])), Re = n(() => me(r(s), (e) => {
      if (e.sorter === !0)
        return e.key || e?.dataIndex;
    }).filter(Boolean)), xe = n(() => me(r(s), (e) => {
      if (e.filters && !e.onFilter)
        return e.key || e?.dataIndex;
    }).filter(Boolean)), Ce = n(() => b(t.dataSource) ? S.records : t.dataSource), Te = n(() => pe(t.manual) ? t.manual : Ze(y.searchFormExtra?.() || []).some((a) => a.type?.name === "ApView")), {
      rowSelection: T,
      selectedRows: F,
      ...B
    } = nt({
      fixed: !0,
      ...t.rowSelection === !0 ? {} : t.rowSelection,
      rowKey: t.rowKey,
      dataSource: Ce
    }), {
      formRef: c,
      submit: V,
      reset: A,
      tableProps: G,
      refresh: J,
      data: S,
      setDataSource: Fe,
      getColumnSFConfig: Q,
      sortedInfo: Be,
      filteredInfo: ke,
      setPaging: ze,
      getPaging: Ie,
      submitWith: X,
      getLastParams: Pe
    } = lt({
      async request(e) {
        if (!T.value.preserveSelectedRowKeys && b(t.dataSource) && !N.value && B.clearAll(), N.value && (N.value = !1), !b(t.dataSource))
          return {
            data: t.dataSource || [],
            total: t.dataSource.length || 0
          };
        const a = await t.request?.(e);
        return t.onLoad?.(a?.data || []), {
          data: a?.data || [],
          total: a?.total || 0
        };
      },
      filterFields: xe,
      sortFields: Re,
      params: Ue(t, "params"),
      defaultData: t.defaultData,
      manual: r(Te),
      formatParams: t.beforeSearchSubmit,
      pagination: t.pagination
    });
    rt({
      columns: n(() => s.value),
      columnsBackup: n(() => U.value),
      size: n(() => C.value),
      updateColumns(e) {
        s.value = e;
      },
      updateSize(e) {
        C.value = e;
      },
      dataSource: n(() => r(S).records),
      getSearchFormValues: _,
      setSearchFormValues: Z,
      submit: V,
      submitWith: X,
      reset: A,
      refresh: J,
      getSearchFormSorterItems: ee,
      setSearchFormSorterItems: te,
      resetSearchFormSorterItems: re,
      getLastParams: Pe
    });
    const Ne = () => {
      let e = t.columns?.filter((o) => !o.hideInTable) || [];
      function a(o, u) {
        return o.map((l) => ({
          resizable: pe(l.resizable) ? l.resizable : t.columnResizable,
          ...ie(gt(l), ["ellipsis"]),
          // tips: 此函数内部依赖查询&筛选的相应式值
          ...Q(l),
          fixed: u ? u.fixed : l.fixed,
          title: pt(l, W("table-header", "title"), y.headerCell, r(be).colorTextTertiary),
          customRender({
            value: h,
            ...w
          }) {
            const oe = ct(l), We = ft({
              ...l,
              valueType: oe
            }, {
              value: h,
              ...w
            }), De = mt(oe, We, w.record, r(D)), ae = l.renderText?.({
              value: h,
              ...w
            }) || h, $e = l.renderText ? m(le, null, [l.renderText?.({
              value: h,
              ...w
            })]) : De;
            let E = Ke(l, ae, $e);
            return l.customRender && (E = l.customRender({
              value: h,
              ...w,
              column: l,
              originalNode: E,
              originalText: ae
            })), E;
          },
          children: a(l.children || [], u || l)
        }));
      }
      return a(e);
    }, Ve = () => {
      function e(a) {
        for (const o of a)
          o.children?.length ? e(o.children) : Q(o, !0);
      }
      e(s.value);
    };
    k(() => [t.columns, t.columnResizable], () => {
      const e = Ne();
      s.value = e, U.value = e;
    }, {
      deep: !0,
      immediate: !0
    }), k(() => [Be.value, ke.value], () => {
      Ve();
    }, {
      deep: !0
    });
    const Ae = n(() => {
      if (t.adaptive && (S.total > 0 || t.dataSource?.length))
        return {
          y: r(we),
          x: t.scroll?.x || "100%"
        };
      if (t.scroll)
        return t.scroll;
    }), Ee = n(() => {
      if (t.tableLayout)
        return t.tableLayout;
      if (t.columns?.some((e) => e.ellipsis))
        return "fixed";
    }), Y = n(() => {
      const e = r(G), a = r(T);
      return {
        ...t,
        ...e,
        rowSelection: t.rowSelection === !0 || t.rowSelection?.mode === "internal" ? {
          ...a,
          // tips 如果是前端分页，则默认会走缓存
          preserveSelectedRowKeys: b(t.dataSource) ? a.preserveSelectedRowKeys : !0
        } : bt(t.rowSelection),
        loading: b(t.loading) ? e.loading : t.loading,
        pagination: t.pagination === !1 ? !1 : e.pagination,
        scroll: r(Ae)
      };
    }), Le = n(() => [i(), t.card ? null : i("wrapper"), t.adaptive ? i("adaptive") : null, H.value && x.value?.visible ? ye(`sticky-${q === 0 ? "absolute" : "relative"}`) : null, he.value].filter(Boolean));
    function Ke(e, a, o) {
      if (ce.includes(e.valueType))
        return o;
      const u = yt(a);
      return e.copyable || e.ellipsis ? m(wt, {
        copyable: e.copyable,
        rawValue: u,
        ellipsis: e.ellipsis ? Ye(e.ellipsis) ? {
          tooltip: o,
          rows: 1
        } : {
          ...e.ellipsis,
          tooltip: o
        } : !1,
        content: o
      }, null) : o;
    }
    k(() => r(S).loading, (e) => {
      t.onLoadingChange?.(e);
    }), k(() => t.dataSource, (e) => {
      Fe(e);
    }, {
      immediate: !0
    });
    function Z(e) {
      c.value?.apForm?.setFieldsValue?.(e);
    }
    function _(e = !1) {
      const a = e ? "getFieldsValueTransformed" : "getFieldsValue";
      return c.value?.apForm?.[a]?.(!0);
    }
    function ee() {
      return c.value?.getSorterItems() || [];
    }
    function te(e) {
      c.value?.setSorterItems(e);
    }
    function re() {
      c.value?.resetSorterItems();
    }
    function Oe() {
      return r(s);
    }
    return ge({
      submit: () => V(),
      reset: () => A(),
      refresh: () => J(),
      submitWith: () => X(),
      setSearchFormValues: Z,
      getSearchFormValues: _,
      setPaging: ze,
      getPaging: Ie,
      getShownColumns: Oe,
      dataSource: n(() => r(S).records),
      rowSelection: {
        selectedRows: n(() => r(F)),
        ...B
      },
      scrollBar: {
        x: {
          getCurrentScroll: () => x?.value?.currentScroll ?? 0,
          scroll: (e) => x?.value?.scroll?.(e)
        },
        y: void 0
      },
      getSearchFormSorterItems: ee,
      setSearchFormSorterItems: te,
      resetSearchFormSorterItems: re
    }), (e, a) => (p(), z("div", {
      ref_key: "tableWrapperRef",
      ref: $,
      class: g(Le.value),
      style: L(r(Se)({
        "scroll-bar-width": `${r(q)}px`
      }))
    }, [r(b)(d.dataSource) && d.searchForm !== !1 && M.value.length > 0 ? (p(), z("div", {
      key: 0,
      class: g(d.card ? r(P)("search-wrapper") : null),
      style: L(d.searchFormWrapperStyle)
    }, [m(r(et).SearchForm, I(d.searchForm || {}, {
      ref_key: "formRef",
      ref: c,
      "custom-reset": "",
      "submit-loading": r(G).loading,
      onSubmit: r(V),
      onReset: r(A)
    }), ne({
      default: v(() => [(p(!0), z(le, null, se(M.value, (o) => (p(), ue(qe(o.renderNode), {
        key: o.dataIndex
      }))), 128))]),
      _: 2
    }, [y.searchFormExtra ? {
      name: "extra",
      fn: v(() => [R(e.$slots, "searchFormExtra")]),
      key: "0"
    } : void 0]), 1040, ["submit-loading", "onSubmit", "onReset"])], 6)) : de("", !0), K("div", {
      ref_key: "contentRef",
      ref: ve,
      class: g([r(P)("table-wrapper"), d.card ? r(P)("table-wrapper-card") : null]),
      style: L(d.tableWrapperStyle)
    }, [K("div", {
      class: g(r(i)("header-wrapper"))
    }, [d.settings ? (p(), z("div", {
      key: 0,
      class: g(r(i)("header"))
    }, [K("div", {
      class: g(r(W)("header", "title"))
    }, [R(e.$slots, "title", I({
      selectedRows: r(F),
      selectedRowKeys: r(T).selectedRowKeys,
      shownColumns: s.value
    }, B))], 2), y.title ? (p(), ue(r(Je), {
      key: 0,
      type: "vertical"
    })) : de("", !0), m(vt, {
      config: d.settings
    }, null, 8, ["config"])], 2)) : R(e.$slots, "title", I({
      key: 1,
      selectedRows: r(F),
      selectedRowKeys: r(T).selectedRowKeys,
      shownColumns: s.value
    }, B))], 2), m(r(Qe), I({
      ref_key: "antdTableRef",
      ref: j,
      class: r(i)("table")
    }, Y.value, {
      size: C.value,
      "table-layout": Ee.value,
      columns: s.value,
      onResizeColumn: a[0] || (a[0] = (o, u) => u.width = o)
    }), ne({
      summary: v(() => [R(e.$slots, "summary", {
        columns: s.value,
        records: Y.value.dataSource,
        selectedRows: r(F)
      })]),
      _: 2
    }, [r(H) ? {
      name: "bottomPaginationTop",
      fn: v(() => [m(r(Rt), {
        ref_key: "scrollBarRef",
        ref: x,
        "scroll-container": j.value?.table?.scrollBodyRef,
        direction: "horizontal",
        "bar-color": "var(--scrollbar-thumb-color-base)",
        "track-color": "var(--table-header-bg, #f2f6f9)",
        "extra-size": C.value === "middle" ? 13 : 10
      }, null, 8, ["scroll-container", "extra-size"])]),
      key: "0"
    } : void 0, se(r(ie)(y, ["title", "searchFormExtra", "headerCell", "summary"]), (o, u) => ({
      name: u,
      fn: v((l) => [R(e.$slots, u, Me(Ge(l || {})))])
    }))]), 1040, ["class", "size", "table-layout", "columns"])], 6)], 6));
  }
});
export {
  Xt as default
};
