import V from "../../../@babel/runtime/helpers/esm/defineProperty.mjs";
import s from "../../../@babel/runtime/helpers/esm/objectSpread2.mjs";
import f from "../../../@babel/runtime/helpers/esm/toConsumableArray.mjs";
import q from "../../../@babel/runtime/helpers/esm/objectWithoutProperties.mjs";
import { useContext as I } from "../../../@rc-component/context/es/context.mjs";
import { fillRef as E } from "../../../rc-util/es/ref.mjs";
import * as l from "react";
import { useMemo as C } from "react";
import J from "../../../classnames/index.mjs";
import K from "../ColGroup.mjs";
import Q from "../context/TableContext.mjs";
import U from "../hooks/useRenderTimes.mjs";
var Y = ["className", "noData", "columns", "flattenColumns", "colWidths", "columCount", "stickyOffsets", "direction", "fixHeader", "stickyTopOffset", "stickyBottomOffset", "stickyClassName", "onScroll", "maxContentScroll", "children"];
function Z(e, u) {
  return C(function() {
    for (var m = [], n = 0; n < u; n += 1) {
      var i = e[n];
      if (i !== void 0)
        m[n] = i;
      else
        return null;
    }
    return m;
  }, [e.join("_"), u]);
}
var H = /* @__PURE__ */ l.forwardRef(function(e, u) {
  process.env.NODE_ENV !== "production" && U(e);
  var m = e.className, n = e.noData, i = e.columns, c = e.flattenColumns, T = e.colWidths, x = e.columCount, d = e.stickyOffsets, k = e.direction, w = e.fixHeader, B = e.stickyTopOffset, D = e.stickyBottomOffset, b = e.stickyClassName, L = e.onScroll, z = e.maxContentScroll, F = e.children, j = q(e, Y), y = I(Q, ["prefixCls", "scrollbarSize", "isSticky"]), P = y.prefixCls, $ = y.scrollbarSize, v = y.isSticky, o = v && !w ? 0 : $, h = l.useRef(null), M = l.useCallback(function(t) {
    E(u, t), E(h, t);
  }, []);
  l.useEffect(function() {
    var t;
    function a(r) {
      var _ = r, R = _.currentTarget, g = _.deltaX;
      g && (L({
        currentTarget: R,
        scrollLeft: R.scrollLeft + g
      }), r.preventDefault());
    }
    return (t = h.current) === null || t === void 0 || t.addEventListener("wheel", a), function() {
      var r;
      (r = h.current) === null || r === void 0 || r.removeEventListener("wheel", a);
    };
  }, []);
  var X = l.useMemo(function() {
    return c.every(function(t) {
      return t.width;
    });
  }, [c]), N = c[c.length - 1], O = {
    fixed: N ? N.fixed : null,
    scrollbar: !0,
    onHeaderCell: function() {
      return {
        className: "".concat(P, "-cell-scrollbar")
      };
    }
  }, A = C(function() {
    return o ? [].concat(f(i), [O]) : i;
  }, [o, i]), W = C(function() {
    return o ? [].concat(f(c), [O]) : c;
  }, [o, c]), G = C(function() {
    var t = d.right, a = d.left;
    return s(s({}, d), {}, {
      left: k === "rtl" ? [].concat(f(a.map(function(r) {
        return r + o;
      })), [0]) : a,
      right: k === "rtl" ? t : [].concat(f(t.map(function(r) {
        return r + o;
      })), [0]),
      isSticky: v
    });
  }, [o, d, v]), S = Z(T, x);
  return /* @__PURE__ */ l.createElement("div", {
    style: s({
      overflow: "hidden"
    }, v ? {
      top: B,
      bottom: D
    } : {}),
    ref: M,
    className: J(m, V({}, b, !!b))
  }, /* @__PURE__ */ l.createElement("table", {
    style: {
      tableLayout: "fixed",
      visibility: n || S ? null : "hidden"
    }
  }, (!n || !z || X) && /* @__PURE__ */ l.createElement(K, {
    colWidths: S ? [].concat(f(S), [o]) : [],
    columCount: x + 1,
    columns: W
  }), F(s(s({}, j), {}, {
    stickyOffsets: G,
    columns: A,
    flattenColumns: W
  }))));
});
H.displayName = "FixedHolder";
const fe = /* @__PURE__ */ l.memo(H);
export {
  fe as default
};
