import S from "../../@babel/runtime/helpers/esm/defineProperty.mjs";
import H from "../../@babel/runtime/helpers/esm/extends.mjs";
import x from "../../@babel/runtime/helpers/esm/slicedToArray.mjs";
import u from "../../@babel/runtime/helpers/esm/objectSpread2.mjs";
import ye from "../../classnames/index.mjs";
import Jt from "../../rc-resize-observer/es/index.mjs";
import Qt from "../../rc-util/es/Dom/isVisible.mjs";
import { isStyleSupport as Zt } from "../../rc-util/es/Dom/styleChecker.mjs";
import { getTargetScrollBarSize as it } from "../../rc-util/es/getScrollBarSize.mjs";
import er from "../../rc-util/es/hooks/useEvent.mjs";
import st from "../../rc-util/es/pickAttrs.mjs";
import tr from "../../rc-util/es/utils/get.mjs";
import { warningOnce as J } from "../../rc-util/es/warning.mjs";
import * as e from "react";
import rr from "./Body/index.mjs";
import or from "./ColGroup.mjs";
import { EXPAND_COLUMN as nr, INTERNAL_HOOKS as dt } from "./constant.mjs";
import ar, { makeImmutable as lr } from "./context/TableContext.mjs";
import ct from "./FixedHolder/index.mjs";
import Q, { FooterComponents as ir } from "./Footer/index.mjs";
import sr from "./Footer/Summary.mjs";
import ut from "./Header/Header.mjs";
import cr from "./hooks/useColumns/index.mjs";
import ur from "./hooks/useExpand.mjs";
import fr from "./hooks/useFixedInfo.mjs";
import { useLayoutState as mr, useTimeoutLock as dr } from "./hooks/useFrame.mjs";
import pr from "./hooks/useHover.mjs";
import vr from "./hooks/useSticky.mjs";
import yr from "./hooks/useStickyOffsets.mjs";
import ft from "./Panel/index.mjs";
import xr from "./stickyScrollBar.mjs";
import Sr from "./sugar/Column.mjs";
import Rr from "./sugar/ColumnGroup.mjs";
import { getColumnsKey as Cr, validateValue as mt } from "./utils/valueUtil.mjs";
var Er = "rc-table", hr = [], gr = {};
function wr() {
  return "No Data";
}
function Tr(Z, vt) {
  var f, o = u({
    rowKey: "key",
    prefixCls: Er,
    emptyText: wr
  }, Z), a = o.prefixCls, yt = o.className, xe = o.rowClassName, xt = o.style, Se = o.data, D = o.rowKey, R = o.scroll, K = o.tableLayout, C = o.direction, Re = o.title, Ce = o.footer, B = o.summary, ee = o.caption, St = o.id, Ee = o.showHeader, he = o.components, A = o.emptyText, ge = o.onRow, Rt = o.onHeaderRow, Ct = o.internalHooks, Et = o.transformColumns, we = o.internalRefs, Te = o.tailor, be = o.getContainerWidth, ht = o.sticky, v = Se || hr, Ne = !!v.length, I = Ct === dt;
  process.env.NODE_ENV !== "production" && (["onRowClick", "onRowDoubleClick", "onRowContextMenu", "onRowMouseEnter", "onRowMouseLeave"].forEach(function(t) {
    J(o[t] === void 0, "`".concat(t, "` is removed, please use `onRow` instead."));
  }), J(!("getBodyWrapper" in o), "`getBodyWrapper` is deprecated, please use custom `components` instead."));
  var P = e.useCallback(function(t, r) {
    return tr(he, t) || r;
  }, [he]), O = e.useMemo(function() {
    return typeof D == "function" ? D : function(t) {
      var r = t && t[D];
      return process.env.NODE_ENV !== "production" && J(r !== void 0, "Each record in table should have a unique `key` prop, or set `rowKey` to an unique primary key."), r;
    };
  }, [D]), ke = P(["body"]), gt = pr(), te = x(gt, 3), _e = te[0], Le = te[1], He = te[2], wt = ur(o, v, O), N = x(wt, 6), l = N[0], Ie = N[1], re = N[2], oe = N[3], Oe = N[4], ne = N[5], ae = R == null ? void 0 : R.x, Tt = e.useState(0), We = x(Tt, 2), V = We[0], bt = We[1], Nt = cr(u(u(u({}, o), l), {}, {
    expandable: !!l.expandedRowRender,
    columnTitle: l.columnTitle,
    expandedKeys: re,
    getRowKey: O,
    // https://github.com/ant-design/ant-design/issues/23894
    onTriggerExpand: ne,
    expandIcon: oe,
    expandIconColumnIndex: l.expandIconColumnIndex,
    direction: C,
    scrollWidth: I && Te && typeof ae == "number" ? ae : null,
    clientWidth: V
  }), I ? Et : null), le = x(Nt, 3), E = le[0], n = le[1], ie = le[2], g = ie ?? ae, ze = e.useMemo(function() {
    return {
      columns: E,
      flattenColumns: n
    };
  }, [E, n]), w = e.useRef(), se = e.useRef(), i = e.useRef(), Me = e.useRef();
  e.useImperativeHandle(vt, function() {
    return {
      nativeElement: w.current,
      scrollTo: function(r) {
        var c;
        if (i.current instanceof HTMLElement) {
          var s = r.index, p = r.top, L = r.key;
          if (p) {
            var T;
            (T = i.current) === null || T === void 0 || T.scrollTo({
              top: p
            });
          } else {
            var b, M = L ?? O(v[s]);
            (b = i.current.querySelector('[data-row-key="'.concat(M, '"]'))) === null || b === void 0 || b.scrollIntoView();
          }
        } else
          (c = i.current) !== null && c !== void 0 && c.scrollTo && i.current.scrollTo(r);
      }
    };
  });
  var Fe = e.useRef(), kt = e.useState(!1), De = x(kt, 2), _t = De[0], X = De[1], Lt = e.useState(!1), Ke = x(Lt, 2), Ht = Ke[0], G = Ke[1], It = mr(/* @__PURE__ */ new Map()), Be = x(It, 2), Ot = Be[0], Wt = Be[1], zt = Cr(n), Ae = zt.map(function(t) {
    return Ot.get(t);
  }), Pe = e.useMemo(function() {
    return Ae;
  }, [Ae.join("_")]), Y = yr(Pe, n.length, C), m = R && mt(R.y), y = R && mt(g) || !!l.fixed, W = y && n.some(function(t) {
    var r = t.fixed;
    return r;
  }), Ve = e.useRef(), k = vr(ht, a), h = k.isSticky, Mt = k.offsetHeader, Ft = k.offsetSummary, Dt = k.offsetScroll, Kt = k.stickyClassName, Bt = k.container, d = e.useMemo(function() {
    return B == null ? void 0 : B(v);
  }, [B, v]), z = (m || h) && /* @__PURE__ */ e.isValidElement(d) && d.type === sr && d.props.fixed, ce, $, ue;
  m && ($ = {
    overflowY: "scroll",
    maxHeight: R.y
  }), y && (ce = {
    overflowX: "auto"
  }, m || ($ = {
    overflowY: "hidden"
  }), ue = {
    width: g === !0 ? "auto" : g,
    minWidth: "100%"
  });
  var Xe = e.useCallback(function(t, r) {
    Qt(w.current) && Wt(function(c) {
      if (c.get(t) !== r) {
        var s = new Map(c);
        return s.set(t, r), s;
      }
      return c;
    });
  }, []), At = dr(null), Ge = x(At, 2), Pt = Ge[0], Ye = Ge[1];
  function q(t, r) {
    r && (typeof r == "function" ? r(t) : r.scrollLeft !== t && (r.scrollLeft = t, r.scrollLeft !== t && setTimeout(function() {
      r.scrollLeft = t;
    }, 0)));
  }
  var _ = er(function(t) {
    var r = t.currentTarget, c = t.scrollLeft, s = C === "rtl", p = typeof c == "number" ? c : r.scrollLeft, L = r || gr;
    if (!Ye() || Ye() === L) {
      var T;
      Pt(L), q(p, se.current), q(p, i.current), q(p, Fe.current), q(p, (T = Ve.current) === null || T === void 0 ? void 0 : T.setScrollLeft);
    }
    var b = r || se.current;
    if (b) {
      var M = b.scrollWidth, ve = b.clientWidth;
      if (M === ve) {
        X(!1), G(!1);
        return;
      }
      s ? (X(-p < M - ve), G(-p > 0)) : (X(p > 0), G(p < M - ve));
    }
  }), $e = function() {
    y && i.current ? _({
      currentTarget: i.current
    }) : (X(!1), G(!1));
  }, Vt = function(r) {
    var c = r.width, s = w.current ? w.current.offsetWidth : c;
    I && be && w.current && (s = be(w.current, s) || s), s !== V && ($e(), bt(s));
  }, qe = e.useRef(!1);
  e.useEffect(function() {
    qe.current && $e();
  }, [y, Se, E.length]), e.useEffect(function() {
    qe.current = !0;
  }, []);
  var Xt = e.useState(0), Ue = x(Xt, 2), U = Ue[0], je = Ue[1], Gt = e.useState(!0), Je = x(Gt, 2), Qe = Je[0], Yt = Je[1];
  e.useEffect(function() {
    (!Te || !I) && (i.current instanceof Element ? je(it(i.current).width) : je(it(Me.current).width)), Yt(Zt("position", "sticky"));
  }, []), e.useEffect(function() {
    I && we && (we.body.current = i.current);
  });
  var $t = e.useCallback(function(t) {
    return /* @__PURE__ */ e.createElement(e.Fragment, null, /* @__PURE__ */ e.createElement(ut, t), z === "top" && /* @__PURE__ */ e.createElement(Q, t, d));
  }, [z, d]), qt = e.useCallback(function(t) {
    return /* @__PURE__ */ e.createElement(Q, t, d);
  }, [d]), Ze = P(["table"], "table"), j = e.useMemo(function() {
    return K || (W ? g === "max-content" ? "auto" : "fixed" : m || h || n.some(function(t) {
      var r = t.ellipsis;
      return r;
    }) ? "fixed" : "auto");
  }, [m, W, n, K, h]), fe, me = {
    colWidths: Pe,
    columCount: n.length,
    stickyOffsets: Y,
    onHeaderRow: Rt,
    fixHeader: m,
    scroll: R
  }, et = e.useMemo(function() {
    return Ne ? null : typeof A == "function" ? A() : A;
  }, [Ne, A]), tt = /* @__PURE__ */ e.createElement(rr, {
    data: v,
    measureColumnWidth: m || y || h
  }), rt = /* @__PURE__ */ e.createElement(or, {
    colWidths: n.map(function(t) {
      var r = t.width;
      return r;
    }),
    columns: n
  }), ot = ee != null ? /* @__PURE__ */ e.createElement("caption", {
    className: "".concat(a, "-caption")
  }, ee) : void 0, Ut = st(o, {
    data: !0
  }), nt = st(o, {
    aria: !0
  });
  if (m || h) {
    var de;
    typeof ke == "function" ? (de = ke(v, {
      scrollbarSize: U,
      ref: i,
      onScroll: _
    }), me.colWidths = n.map(function(t, r) {
      var c = t.width, s = r === n.length - 1 ? c - U : c;
      return typeof s == "number" && !Number.isNaN(s) ? s : (process.env.NODE_ENV !== "production" && J(o.columns.length === 0, "When use `components.body` with render props. Each column should have a fixed `width` value."), 0);
    })) : de = /* @__PURE__ */ e.createElement("div", {
      style: u(u({}, ce), $),
      onScroll: _,
      ref: i,
      className: ye("".concat(a, "-body"))
    }, /* @__PURE__ */ e.createElement(Ze, H({
      style: u(u({}, ue), {}, {
        tableLayout: j
      })
    }, nt), ot, rt, tt, !z && d && /* @__PURE__ */ e.createElement(Q, {
      stickyOffsets: Y,
      flattenColumns: n,
      columns: E
    }, d)));
    var at = u(u(u({
      noData: !v.length,
      maxContentScroll: y && g === "max-content"
    }, me), ze), {}, {
      direction: C,
      stickyClassName: Kt,
      onScroll: _
    });
    fe = /* @__PURE__ */ e.createElement(e.Fragment, null, Ee !== !1 && /* @__PURE__ */ e.createElement(ct, H({}, at, {
      stickyTopOffset: Mt,
      className: "".concat(a, "-header"),
      ref: se
    }), $t), de, z && z !== "top" && /* @__PURE__ */ e.createElement(ct, H({}, at, {
      stickyBottomOffset: Ft,
      className: "".concat(a, "-summary"),
      ref: Fe
    }), qt), h && i.current && i.current instanceof Element && /* @__PURE__ */ e.createElement(xr, {
      ref: Ve,
      offsetScroll: Dt,
      scrollBodyRef: i,
      onScroll: _,
      container: Bt
    }));
  } else
    fe = /* @__PURE__ */ e.createElement("div", {
      style: u(u({}, ce), $),
      className: ye("".concat(a, "-content")),
      onScroll: _,
      ref: i
    }, /* @__PURE__ */ e.createElement(Ze, H({
      style: u(u({}, ue), {}, {
        tableLayout: j
      })
    }, nt), ot, rt, Ee !== !1 && /* @__PURE__ */ e.createElement(ut, H({}, me, ze)), tt, d && /* @__PURE__ */ e.createElement(Q, {
      stickyOffsets: Y,
      flattenColumns: n,
      columns: E
    }, d)));
  var pe = /* @__PURE__ */ e.createElement("div", H({
    className: ye(a, yt, (f = {}, S(f, "".concat(a, "-rtl"), C === "rtl"), S(f, "".concat(a, "-ping-left"), _t), S(f, "".concat(a, "-ping-right"), Ht), S(f, "".concat(a, "-layout-fixed"), K === "fixed"), S(f, "".concat(a, "-fixed-header"), m), S(f, "".concat(a, "-fixed-column"), W), S(f, "".concat(a, "-scroll-horizontal"), y), S(f, "".concat(a, "-has-fix-left"), n[0] && n[0].fixed), S(f, "".concat(a, "-has-fix-right"), n[n.length - 1] && n[n.length - 1].fixed === "right"), f)),
    style: xt,
    id: St,
    ref: w
  }, Ut), Re && /* @__PURE__ */ e.createElement(ft, {
    className: "".concat(a, "-title")
  }, Re(v)), /* @__PURE__ */ e.createElement("div", {
    ref: Me,
    className: "".concat(a, "-container")
  }, fe), Ce && /* @__PURE__ */ e.createElement(ft, {
    className: "".concat(a, "-footer")
  }, Ce(v)));
  y && (pe = /* @__PURE__ */ e.createElement(Jt, {
    onResize: Vt
  }, pe));
  var lt = fr(n, Y, C, E), jt = e.useMemo(function() {
    return {
      // Scroll
      scrollX: g,
      // Table
      prefixCls: a,
      getComponent: P,
      scrollbarSize: U,
      direction: C,
      fixedInfoList: lt,
      isSticky: h,
      supportSticky: Qe,
      componentWidth: V,
      fixHeader: m,
      fixColumn: W,
      horizonScroll: y,
      // Body
      tableLayout: j,
      rowClassName: xe,
      expandedRowClassName: l.expandedRowClassName,
      expandIcon: oe,
      expandableType: Ie,
      expandRowByClick: l.expandRowByClick,
      expandedRowRender: l.expandedRowRender,
      onTriggerExpand: ne,
      expandIconColumnIndex: l.expandIconColumnIndex,
      indentSize: l.indentSize,
      allColumnsFixedLeft: n.every(function(t) {
        return t.fixed === "left";
      }),
      emptyNode: et,
      // Column
      columns: E,
      flattenColumns: n,
      onColumnResize: Xe,
      // Row
      hoverStartRow: _e,
      hoverEndRow: Le,
      onHover: He,
      rowExpandable: l.rowExpandable,
      onRow: ge,
      getRowKey: O,
      expandedKeys: re,
      childrenColumnName: Oe
    };
  }, [
    // Scroll
    g,
    // Table
    a,
    P,
    U,
    C,
    lt,
    h,
    Qe,
    V,
    m,
    W,
    y,
    // Body
    j,
    xe,
    l.expandedRowClassName,
    oe,
    Ie,
    l.expandRowByClick,
    l.expandedRowRender,
    ne,
    l.expandIconColumnIndex,
    l.indentSize,
    et,
    // Column
    E,
    n,
    Xe,
    // Row
    _e,
    Le,
    He,
    l.rowExpandable,
    ge,
    O,
    re,
    Oe
  ]);
  return /* @__PURE__ */ e.createElement(ar.Provider, {
    value: jt
  }, pe);
}
var pt = /* @__PURE__ */ e.forwardRef(Tr);
process.env.NODE_ENV !== "production" && (pt.displayName = "Table");
function br(Z) {
  return lr(pt, Z);
}
var F = br();
F.EXPAND_COLUMN = nr;
F.INTERNAL_HOOKS = dt;
F.Column = Sr;
F.ColumnGroup = Rr;
F.Summary = ir;
export {
  Er as DEFAULT_PREFIX,
  F as default,
  br as genTable
};
