import * as o from "react";
import g from "../../../classnames/index.mjs";
import { INTERNAL_HOOKS as qe } from "../../../rc-table/es/constant.mjs";
import "../../../rc-table/es/Footer/index.mjs";
import "../../../rc-table/es/Table.mjs";
import "../../../rc-util/es/warning.mjs";
import "../../../rc-table/es/VirtualTable/index.mjs";
import { convertChildrenToColumns as Je } from "../../../rc-table/es/hooks/useColumns/index.mjs";
import Qe from "../../../rc-util/es/omit.mjs";
import et from "../_util/hooks/useProxyImperativeHandle.mjs";
import tt from "../_util/scrollTo.mjs";
import { devUseWarning as ot } from "../_util/warning.mjs";
import { ConfigContext as nt } from "../config-provider/context.mjs";
import rt from "../config-provider/defaultRenderEmpty.mjs";
import st from "../config-provider/hooks/useCSSVarCls.mjs";
import it from "../config-provider/hooks/useSize.mjs";
import at from "../grid/hooks/useBreakpoint.mjs";
import lt from "../locale/en_US.mjs";
import ct from "../pagination/Pagination.mjs";
import mt from "../spin/index.mjs";
import "../../../@ant-design/cssinjs/es/extractStyle.mjs";
import "../../../@ant-design/cssinjs/es/hooks/useCacheToken.mjs";
import "../../../@ant-design/cssinjs/es/StyleContext.mjs";
import "../../../@ant-design/cssinjs/es/theme/createTheme.mjs";
import "../../../@ant-design/cssinjs/es/theme/ThemeCache.mjs";
import "../../../@ant-design/cssinjs/es/hooks/useCompatibleInsertionEffect.mjs";
import "../../../@ant-design/cssinjs/es/hooks/useEffectCleanupRegister.mjs";
import "../../../@ant-design/cssinjs/es/hooks/useHMR.mjs";
import "../../../@ant-design/cssinjs/es/transformers/legacyLogicalProperties.mjs";
import pt from "../theme/useToken.mjs";
import dt from "./ExpandIcon.mjs";
import ut from "./hooks/useContainerWidth.mjs";
import ft, { getFilterData as de } from "./hooks/useFilter/index.mjs";
import gt from "./hooks/useLazyKVMap.mjs";
import Ct, { getPaginationParam as bt, DEFAULT_PAGE_SIZE as ht } from "./hooks/usePagination.mjs";
import St from "./hooks/useSelection.mjs";
import vt, { getSortData as ue } from "./hooks/useSorter.mjs";
import xt from "./hooks/useTitleColumns.mjs";
import yt from "./RcTable/index.mjs";
import Nt from "./RcTable/VirtualTable.mjs";
import Pt from "./style/index.mjs";
const wt = [], Et = (A, fe) => {
  const {
    prefixCls: ge,
    className: Ce,
    rootClassName: K,
    style: be,
    size: he,
    bordered: Se,
    dropdownPrefixCls: ve,
    dataSource: xe,
    pagination: d,
    rowSelection: T,
    rowKey: C = "key",
    rowClassName: I,
    columns: W,
    children: B,
    childrenColumnName: ye,
    onChange: R,
    getPopupContainer: U,
    loading: y,
    expandIcon: Ne,
    expandable: z,
    expandedRowRender: Pe,
    expandIconColumnIndex: we,
    indentSize: G,
    scroll: X,
    sortDirections: Ee,
    locale: j,
    showSorterTooltip: Oe = !0,
    virtual: Y
  } = A, D = ot("Table");
  process.env.NODE_ENV !== "production" && process.env.NODE_ENV !== "production" && D(!(typeof C == "function" && C.length > 1), "usage", "`index` parameter of `rowKey` function is deprecated. There is no guarantee that it will work as expected.");
  const N = o.useMemo(() => W || Je(B), [W, B]), Te = o.useMemo(() => N.some((e) => e.responsive), [N]), _ = at(Te), M = o.useMemo(() => {
    const e = new Set(Object.keys(_).filter((t) => _[t]));
    return N.filter((t) => !t.responsive || t.responsive.some((s) => e.has(s)));
  }, [N, _]), Ie = Qe(A, ["className", "style", "columns"]), {
    locale: Re = lt,
    direction: $,
    table: b,
    renderEmpty: k,
    getPrefixCls: Z,
    getPopupContainer: q
  } = o.useContext(nt), h = it(he), P = Object.assign(Object.assign({}, Re.Table), j), f = xe || wt, r = Z("table", ge), ze = Z("dropdown", ve), [, J] = pt(), w = st(r), [je, Q, ee] = Pt(r, w), a = Object.assign({
    childrenColumnName: ye,
    expandIconColumnIndex: we
  }, z), {
    childrenColumnName: S = "children"
  } = a, te = o.useMemo(() => f.some((e) => e == null ? void 0 : e[S]) ? "nest" : Pe || z && z.expandedRowRender ? "row" : null, [f]), L = {
    body: o.useRef()
  }, De = ut(r), oe = o.useRef(null), ne = o.useRef(null);
  et(fe, () => Object.assign(Object.assign({}, ne.current), {
    nativeElement: oe.current
  }));
  const E = o.useMemo(() => typeof C == "function" ? C : (e) => e == null ? void 0 : e[C], [C]), [_e] = gt(f, S, E), m = {}, V = function(e, t) {
    let s = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : !1;
    var i, l, c;
    const p = Object.assign(Object.assign({}, m), e);
    s && ((i = m.resetPagination) === null || i === void 0 || i.call(m), !((l = p.pagination) === null || l === void 0) && l.current && (p.pagination.current = 1), d && d.onChange && d.onChange(1, (c = p.pagination) === null || c === void 0 ? void 0 : c.pageSize)), X && X.scrollToFirstRowOnChange !== !1 && L.body.current && tt(0, {
      getContainer: () => L.body.current
    }), R == null || R(p.pagination, p.filters, p.sorter, {
      currentDataSource: de(ue(f, p.sorterStates, S), p.filterStates),
      action: t
    });
  }, Me = (e, t) => {
    V({
      sorter: e,
      sorterStates: t
    }, "sort", !1);
  }, [re, F, se, $e] = vt({
    prefixCls: r,
    mergedColumns: M,
    onSorterChange: Me,
    sortDirections: Ee || ["ascend", "descend"],
    tableLocale: P,
    showSorterTooltip: Oe
  }), ke = o.useMemo(() => ue(f, F, S), [f, F]);
  m.sorter = $e(), m.sorterStates = F;
  const Le = (e, t) => {
    V({
      filters: e,
      filterStates: t
    }, "filter", !0);
  }, [ie, ae, v] = ft({
    prefixCls: r,
    locale: P,
    dropdownPrefixCls: ze,
    mergedColumns: M,
    onFilterChange: Le,
    getPopupContainer: U || q,
    rootClassName: g(K, w)
  }), u = de(ke, ae);
  m.filters = v, m.filterStates = ae;
  const Ve = o.useMemo(() => {
    const e = {};
    return Object.keys(v).forEach((t) => {
      v[t] !== null && (e[t] = v[t]);
    }), Object.assign(Object.assign({}, se), {
      filters: e
    });
  }, [se, v]), [Fe] = xt(Ve), He = (e, t) => {
    V({
      pagination: Object.assign(Object.assign({}, m.pagination), {
        current: e,
        pageSize: t
      })
    }, "paginate");
  }, [n, Ae] = Ct(u.length, He, d);
  m.pagination = d === !1 ? {} : bt(n, d), m.resetPagination = Ae;
  const le = o.useMemo(() => {
    if (d === !1 || !n.pageSize)
      return u;
    const {
      current: e = 1,
      total: t,
      pageSize: s = ht
    } = n;
    return process.env.NODE_ENV !== "production" && D(e > 0, "usage", "`current` should be positive number."), u.length < t ? u.length > s ? (process.env.NODE_ENV !== "production" && D(!1, "usage", "`dataSource` length is less than `pagination.total` but large than `pagination.pageSize`. Please make sure your config correct data with async mode."), u.slice((e - 1) * s, e * s)) : u : u.slice((e - 1) * s, e * s);
  }, [!!d, u, n && n.current, n && n.pageSize, n && n.total]), [ce, Ke] = St({
    prefixCls: r,
    data: u,
    pageData: le,
    getRowKey: E,
    getRecordByKey: _e,
    expandType: te,
    childrenColumnName: S,
    locale: P,
    getPopupContainer: U || q
  }, T), We = (e, t, s) => {
    let i;
    return typeof I == "function" ? i = g(I(e, t, s)) : i = g(I), g({
      [`${r}-row-selected`]: Ke.has(E(e, t))
    }, i);
  };
  a.__PARENT_RENDER_ICON__ = a.expandIcon, a.expandIcon = a.expandIcon || Ne || dt(P), te === "nest" && a.expandIconColumnIndex === void 0 ? a.expandIconColumnIndex = T ? 1 : 0 : a.expandIconColumnIndex > 0 && T && (a.expandIconColumnIndex -= 1), typeof a.indentSize != "number" && (a.indentSize = typeof G == "number" ? G : 15);
  const Be = o.useCallback((e) => Fe(ce(ie(re(e)))), [re, ie, ce]);
  let me, O;
  if (d !== !1 && (n != null && n.total)) {
    let e;
    n.size ? e = n.size : e = h === "small" || h === "middle" ? "small" : void 0;
    const t = (l) => /* @__PURE__ */ o.createElement(ct, Object.assign({}, n, {
      className: g(`${r}-pagination ${r}-pagination-${l}`, n.className),
      size: e
    })), s = $ === "rtl" ? "left" : "right", {
      position: i
    } = n;
    if (i !== null && Array.isArray(i)) {
      const l = i.find((x) => x.includes("top")), c = i.find((x) => x.includes("bottom")), p = i.every((x) => `${x}` == "none");
      !l && !c && !p && (O = t(s)), l && (me = t(l.toLowerCase().replace("top", ""))), c && (O = t(c.toLowerCase().replace("bottom", "")));
    } else
      O = t(s);
  }
  let H;
  typeof y == "boolean" ? H = {
    spinning: y
  } : typeof y == "object" && (H = Object.assign({
    spinning: !0
  }, y));
  const Ue = g(ee, w, `${r}-wrapper`, b == null ? void 0 : b.className, {
    [`${r}-wrapper-rtl`]: $ === "rtl"
  }, Ce, K, Q), Ge = Object.assign(Object.assign({}, b == null ? void 0 : b.style), be), Xe = j && j.emptyText || (k == null ? void 0 : k("Table")) || /* @__PURE__ */ o.createElement(rt, {
    componentName: "Table"
  }), Ye = Y ? Nt : yt, pe = {}, Ze = o.useMemo(() => {
    const {
      fontSize: e,
      lineHeight: t,
      padding: s,
      paddingXS: i,
      paddingSM: l
    } = J, c = Math.floor(e * t);
    switch (h) {
      case "large":
        return s * 2 + c;
      case "small":
        return i * 2 + c;
      default:
        return l * 2 + c;
    }
  }, [J, h]);
  return Y && (pe.listItemHeight = Ze), je(/* @__PURE__ */ o.createElement("div", {
    ref: oe,
    className: Ue,
    style: Ge
  }, /* @__PURE__ */ o.createElement(mt, Object.assign({
    spinning: !1
  }, H), me, /* @__PURE__ */ o.createElement(Ye, Object.assign({}, pe, Ie, {
    ref: ne,
    columns: M,
    direction: $,
    expandable: a,
    prefixCls: r,
    className: g({
      [`${r}-middle`]: h === "middle",
      [`${r}-small`]: h === "small",
      [`${r}-bordered`]: Se,
      [`${r}-empty`]: f.length === 0
    }, ee, w, Q),
    data: le,
    rowKey: E,
    rowClassName: We,
    emptyText: Xe,
    // Internal
    internalHooks: qe,
    internalRefs: L,
    transformColumns: Be,
    getContainerWidth: De
  })), O)));
}, fo = /* @__PURE__ */ o.forwardRef(Et);
export {
  fo as default
};
