import { useContext as w } from "../../../@rc-component/context/es/context.mjs";
import * as v from "react";
import "../../../rc-util/node_modules/react-is/index.mjs";
import S, { responseImmutable as g } from "../context/TableContext.mjs";
import R from "../hooks/useRenderTimes.mjs";
import H from "./HeaderRow.mjs";
function k(s) {
  var t = [];
  function f(u, r) {
    var n = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : 0;
    t[n] = t[n] || [];
    var m = r, d = u.filter(Boolean).map(function(e) {
      var o = {
        key: e.key,
        className: e.className || "",
        children: e.title,
        column: e,
        colStart: m
      }, a = 1, i = e.children;
      return i && i.length > 0 && (a = f(i, m, n + 1).reduce(function(C, h) {
        return C + h;
      }, 0), o.hasSubColumns = !0), "colSpan" in e && (a = e.colSpan), "rowSpan" in e && (o.rowSpan = e.rowSpan), o.colSpan = a, o.colEnd = o.colStart + a - 1, t[n].push(o), m += a, a;
    });
    return d;
  }
  f(s, 0);
  for (var p = t.length, c = function(r) {
    t[r].forEach(function(n) {
      !("rowSpan" in n) && !n.hasSubColumns && (n.rowSpan = p - r);
    });
  }, l = 0; l < p; l += 1)
    c(l);
  return t;
}
function x(s) {
  process.env.NODE_ENV !== "production" && R(s);
  var t = s.stickyOffsets, f = s.columns, p = s.flattenColumns, c = s.onHeaderRow, l = w(S, ["prefixCls", "getComponent"]), u = l.prefixCls, r = l.getComponent, n = v.useMemo(function() {
    return k(f);
  }, [f]), m = r(["header", "wrapper"], "thead"), d = r(["header", "row"], "tr"), e = r(["header", "cell"], "th"), o = r(["header", "cell"], "td");
  return /* @__PURE__ */ v.createElement(m, {
    className: "".concat(u, "-thead")
  }, n.map(function(a, i) {
    var C = /* @__PURE__ */ v.createElement(H, {
      key: i,
      flattenColumns: p,
      cells: a,
      stickyOffsets: t,
      rowComponent: d,
      cellComponent: e,
      tdCellComponent: o,
      onHeaderRow: c,
      index: i
    });
    return C;
  }));
}
const _ = g(x);
export {
  _ as default
};
