"use strict";
const React = require("react");
const checkbox = require("../../Checkbox/checkbox.js");
const column = require("./column.js");
const classNames = require("../../_util/classNames.js");
const useComponent = require("../hooks/useComponent.js");
const constant = require("../constant.js");
const index = require("../../ConfigProvider/index.js");
const emotionReactJsxRuntime_browser_esm = require("../../../../../../../@emotion_react@11.10.4_3toe27fv7etiytxb5kxc7fxaw4/node_modules/@emotion/react/jsx-runtime/dist/emotion-react-jsx-runtime.browser.esm.js");
const _interopDefaultLegacy = (e) => e && typeof e === "object" && "default" in e ? e : { default: e };
const React__default = /* @__PURE__ */ _interopDefaultLegacy(React);
var __assign = globalThis && globalThis.__assign || function() {
  __assign = Object.assign || function(t) {
    for (var s, i = 1, n = arguments.length; i < n; i++) {
      s = arguments[i];
      for (var p in s)
        if (Object.prototype.hasOwnProperty.call(s, p))
          t[p] = s[p];
    }
    return t;
  };
  return __assign.apply(this, arguments);
};
function THead(props) {
  var sorter = props.sorter, expandedRowRender = props.expandedRowRender, _a = props.expandProps, expandProps = _a === void 0 ? {} : _a, onSort = props.onSort, onHandleFilter = props.onHandleFilter, onHandleFilterReset = props.onHandleFilterReset, onHeaderRow = props.onHeaderRow, prefixCls = props.prefixCls, currentFilters = props.currentFilters, components = props.components, data = props.data, selectedRowKeys = props.selectedRowKeys, rowSelection = props.rowSelection, _b = props.allSelectedRowKeys, allSelectedRowKeys = _b === void 0 ? [] : _b, groupColumns = props.groupColumns, stickyOffsets = props.stickyOffsets, groupStickyClassNames = props.groupStickyClassNames, showSorterTooltip = props.showSorterTooltip;
  var rtl = React.useContext(index.ConfigContext).rtl;
  var _c = useComponent(components), ComponentThead = _c.ComponentThead, ComponentHeaderRow = _c.ComponentHeaderRow, getHeaderComponentOperations = _c.getHeaderComponentOperations;
  var _checkbox = rowSelection && (rowSelection.type === "checkbox" || !("type" in rowSelection));
  var _checkAll = rowSelection && "checkAll" in rowSelection ? rowSelection.checkAll : true;
  var isRadio = rowSelection && rowSelection.type === "radio";
  var expandColumnTitle = expandProps.columnTitle;
  var currentSelectedRowKeys = React.useMemo(function() {
    var tempSet = new Set(allSelectedRowKeys);
    return selectedRowKeys.filter(function(v) {
      return tempSet.has(v);
    });
  }, [selectedRowKeys, allSelectedRowKeys]);
  var selectionRowSpanProps = groupColumns.length > 1 ? {
    rowSpan: groupColumns.length
  } : {};
  var operationClassName = classNames(prefixCls + "-th", prefixCls + "-operation");
  return /* @__PURE__ */ emotionReactJsxRuntime_browser_esm.jsx(ComponentThead, {
    children: groupColumns.map(function(row, index2) {
      var headerRowProps = onHeaderRow && onHeaderRow(row, index2);
      var selectionNode = (_checkbox || isRadio) && index2 === 0 && /* @__PURE__ */ emotionReactJsxRuntime_browser_esm.jsx("th", {
        className: classNames(operationClassName, prefixCls + "-" + (isRadio ? "radio" : "checkbox")),
        children: /* @__PURE__ */ emotionReactJsxRuntime_browser_esm.jsxs("div", {
          className: prefixCls + "-th-item",
          children: [_checkAll && !isRadio ? /* @__PURE__ */ emotionReactJsxRuntime_browser_esm.jsx(checkbox, {
            indeterminate: data && currentSelectedRowKeys.length > 0 && currentSelectedRowKeys.length !== allSelectedRowKeys.length,
            checked: data && currentSelectedRowKeys.length !== 0 && currentSelectedRowKeys.length === allSelectedRowKeys.length,
            disabled: !allSelectedRowKeys.length,
            onChange: props.onCheckAll
          }) : null, rowSelection && rowSelection.columnTitle]
        })
      });
      var expandNode = expandedRowRender && /* @__PURE__ */ emotionReactJsxRuntime_browser_esm.jsx("th", {
        className: classNames(operationClassName, prefixCls + "-expand"),
        children: expandColumnTitle && /* @__PURE__ */ emotionReactJsxRuntime_browser_esm.jsx("div", {
          className: prefixCls + "-th-item",
          children: expandColumnTitle
        })
      });
      var stickyClassNames = groupStickyClassNames[index2];
      var headerOperations = getHeaderComponentOperations({
        selectionNode,
        expandNode
      });
      return /* @__PURE__ */ emotionReactJsxRuntime_browser_esm.jsx(ComponentHeaderRow, {
        ...__assign({}, headerRowProps, {
          key: index2,
          className: prefixCls + "-tr"
        }),
        children: row.map(function(column$1, colIndex) {
          var _a2;
          var _b2, _c2, _d, _e;
          var stickyOffset = stickyOffsets[colIndex];
          var stickyClassName = stickyClassNames[colIndex];
          if (column$1.$$isOperation) {
            var node = column$1.node;
            var isExtraOperation = true;
            if (column$1.title === constant.INTERNAL_SELECTION_KEY) {
              node = (_b2 = headerOperations.find(function(o) {
                return o.name === "selectionNode";
              })) === null || _b2 === void 0 ? void 0 : _b2.node;
              isExtraOperation = false;
            }
            if (column$1.title === constant.INTERNAL_EXPAND_KEY) {
              node = (_c2 = headerOperations.find(function(o) {
                return o.name === "expandNode";
              })) === null || _c2 === void 0 ? void 0 : _c2.node;
              isExtraOperation = false;
            }
            var operationNode = node;
            return React__default.default.cloneElement(operationNode, __assign(__assign(__assign({
              key: column$1.key || colIndex
            }, operationNode.props), selectionRowSpanProps), {
              className: classNames(isExtraOperation ? operationClassName : "", (_d = operationNode === null || operationNode === void 0 ? void 0 : operationNode.props) === null || _d === void 0 ? void 0 : _d.className, stickyClassName),
              style: __assign(__assign(__assign({}, (_e = operationNode === null || operationNode === void 0 ? void 0 : operationNode.props) === null || _e === void 0 ? void 0 : _e.style), column$1.fixed === "left" ? (_a2 = {}, _a2[rtl ? "right" : "left"] = stickyOffset, _a2) : {}), {
                width: column$1.width,
                minWidth: column$1.width
              })
            }));
          }
          var headerCellProps = column$1.onHeaderCell && column$1.onHeaderCell(column$1, colIndex);
          var columnClassName = classNames(stickyClassName, column$1.className);
          var columnFixedStyle = {};
          if (column$1.fixed === "left") {
            columnFixedStyle[rtl ? "right" : "left"] = stickyOffset;
          }
          if (column$1.fixed === "right") {
            columnFixedStyle[rtl ? "left" : "right"] = stickyOffset;
          }
          return /* @__PURE__ */ emotionReactJsxRuntime_browser_esm.jsx(column, {
            ...__assign({
              key: column$1.key,
              index: colIndex,
              onSort,
              onHandleFilter,
              onHandleFilterReset,
              currentSorter: sorter,
              currentFilters,
              _key: column$1.key || column$1.dataIndex || colIndex
            }, column$1, {
              column: column$1,
              headerCellProps,
              prefixCls,
              components,
              className: columnClassName,
              columnFixedStyle,
              showSorterTooltip
            })
          });
        })
      });
    })
  });
}
module.exports = THead;
//# sourceMappingURL=index.js.map
