"use strict";
const React = require("react");
const checkbox = require("../../Checkbox/checkbox.js");
const radio = require("../../Radio/radio.js");
const is = require("../../_util/is.js");
const utils = require("../utils.js");
const classNames = require("../../_util/classNames.js");
const useComponent = require("../hooks/useComponent.js");
const index$2 = require("../../../icon/react-icon/IconPlus/index.js");
const index$1 = require("../../../icon/react-icon/IconMinus/index.js");
const constant = require("../constant.js");
const index = require("../../ConfigProvider/index.js");
const td = require("./td.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);
};
var __rest = globalThis && globalThis.__rest || function(s, e) {
  var t = {};
  for (var p in s)
    if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
      t[p] = s[p];
  if (s != null && typeof Object.getOwnPropertySymbols === "function")
    for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
      if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
        t[p[i]] = s[p[i]];
    }
  return t;
};
function Tr(props, ref) {
  var _a;
  var expandedRowRender = props.expandedRowRender, onClickExpandBtn = props.onClickExpandBtn, columns = props.columns, components = props.components, onCheck = props.onCheck, onCheckRadio = props.onCheckRadio, prefixCls = props.prefixCls, selectedRowKeys = props.selectedRowKeys, indeterminateKeys = props.indeterminateKeys, rowClassName = props.rowClassName, onRow = props.onRow, rowSelection = props.rowSelection, _b = props.indentSize, indentSize = _b === void 0 ? 16 : _b, currentSorter = props.currentSorter, virtualized = props.virtualized, stickyOffsets = props.stickyOffsets, stickyClassNames = props.stickyClassNames, getRowKey = props.getRowKey, placeholder = props.placeholder, _c = props.expandProps, expandProps = _c === void 0 ? {
    strictTreeData: true
  } : _c, data = props.data, expandedRowKeys = props.expandedRowKeys, childrenColumnName = props.childrenColumnName, record = props.record, index$3 = props.index, type = props.type, shouldRowExpand = props.shouldRowExpand, level = props.level;
  var rtl = React.useContext(index.ConfigContext).rtl;
  var originRecord = utils.getOriginData(record);
  var rowProps = __rest(onRow && onRow(originRecord, index$3) || {}, []);
  var rowK = getRowKey(record);
  var usedSelectedRowKeys = type === "radio" ? selectedRowKeys.slice(0, 1) : selectedRowKeys;
  var trKey = rowK || index$3;
  var checked = usedSelectedRowKeys.indexOf(rowK) > -1;
  var indeterminate = indeterminateKeys.indexOf(rowK) > -1;
  var classNameTr = classNames(prefixCls + "-tr", (_a = {}, _a[prefixCls + "-row-checked"] = checked, _a), rowClassName && rowClassName(originRecord, index$3));
  var checkboxProps = rowSelection && typeof rowSelection.checkboxProps === "function" ? rowSelection.checkboxProps(originRecord) : {};
  var operationClassName = classNames(prefixCls + "-td", prefixCls + "-operation");
  var getPrefixColClassName = function(name) {
    var _a2;
    return classNames(operationClassName, prefixCls + "-" + name, (_a2 = {}, _a2[prefixCls + "-selection-col"] = virtualized && type === "checkbox" || type === "radio", _a2[prefixCls + "-expand-icon-col"] = virtualized && expandedRowRender, _a2));
  };
  function isChildrenNotEmpty(record2) {
    return expandProps.strictTreeData ? is.isArray(record2[childrenColumnName]) && record2[childrenColumnName].length : record2[childrenColumnName] !== void 0;
  }
  function isDataHaveChildren() {
    return data.find(function(d) {
      return isChildrenNotEmpty(d);
    });
  }
  var shouldRenderExpandRow = shouldRowExpand(record, index$3);
  var recordHaveChildren = isChildrenNotEmpty(record);
  var haveTreeData = !virtualized && isDataHaveChildren() && !expandedRowRender;
  var shouldRenderTreeDataExpandRow = haveTreeData && recordHaveChildren;
  var expandRowByClick = expandProps.expandRowByClick;
  var rowClickProps = expandRowByClick && (shouldRenderExpandRow || shouldRenderTreeDataExpandRow) ? {
    onClick: function(e) {
      onClickExpandBtn(rowK);
      rowProps && rowProps.onClick && rowProps.onClick(e);
    }
  } : {};
  var _d = useComponent(components), ComponentBodyRow = _d.ComponentBodyRow, ComponentTd = _d.ComponentTd, getBodyComponentOperations = _d.getBodyComponentOperations;
  var InnerComponentBodyRow = virtualized ? "div" : ComponentBodyRow;
  var InnerComponentTd = virtualized ? "div" : ComponentTd;
  var baseTrProps = __assign(__assign({
    className: classNameTr,
    key: trKey
  }, rowProps), rowClickProps);
  var trProps = is.isString(ComponentBodyRow) ? baseTrProps : __assign(__assign({}, baseTrProps), {
    record,
    index: index$3
  });
  function renderExpandIcon(record2, rowK2) {
    var expandIcon = expandProps.icon;
    var expanded = !!~expandedRowKeys.indexOf(rowK2);
    var onClickProps = {
      onClick: function(e) {
        e.stopPropagation();
        onClickExpandBtn(rowK2);
      }
    };
    return typeof expandIcon === "function" ? expandIcon(__assign({
      expanded,
      record: record2
    }, onClickProps)) : /* @__PURE__ */ emotionReactJsxRuntime_browser_esm.jsx("button", {
      ...__assign({}, onClickProps, {
        type: "button"
      }),
      children: expanded ? /* @__PURE__ */ emotionReactJsxRuntime_browser_esm.jsx(index$1, {}) : /* @__PURE__ */ emotionReactJsxRuntime_browser_esm.jsx(index$2, {})
    });
  }
  var expandNode = expandedRowRender && /* @__PURE__ */ emotionReactJsxRuntime_browser_esm.jsx(InnerComponentTd, {
    className: getPrefixColClassName("expand-icon-cell"),
    children: shouldRenderExpandRow && renderExpandIcon(record, rowK)
  });
  var renderSelectionCell = rowSelection && rowSelection.renderCell;
  var selectionNode;
  var checkboxNode = /* @__PURE__ */ emotionReactJsxRuntime_browser_esm.jsx(checkbox, {
    ...__assign({
      value: rowK,
      onChange: function(check) {
        return onCheck(check, record);
      },
      checked,
      indeterminate
    }, checkboxProps)
  });
  var radioNode = /* @__PURE__ */ emotionReactJsxRuntime_browser_esm.jsx(radio, {
    ...__assign({
      onChange: function() {
        return onCheckRadio(rowK, record);
      },
      value: rowK,
      checked
    }, checkboxProps)
  });
  if (type === "checkbox") {
    selectionNode = /* @__PURE__ */ emotionReactJsxRuntime_browser_esm.jsx(InnerComponentTd, {
      className: getPrefixColClassName("checkbox"),
      children: renderSelectionCell ? renderSelectionCell(checkboxNode, checked, originRecord) : checkboxNode
    });
  }
  if (type === "radio") {
    selectionNode = /* @__PURE__ */ emotionReactJsxRuntime_browser_esm.jsx(InnerComponentTd, {
      className: getPrefixColClassName("radio"),
      children: renderSelectionCell ? renderSelectionCell(radioNode, checked, originRecord) : radioNode
    });
  }
  var bodyOperations = getBodyComponentOperations({
    selectionNode,
    expandNode
  });
  return /* @__PURE__ */ emotionReactJsxRuntime_browser_esm.jsx(InnerComponentBodyRow, {
    ...__assign({}, trProps, {
      ref
    }),
    children: columns.map(function(col, colIndex) {
      var _a2;
      var _b2, _c2, _d2, _e;
      var stickyOffset = stickyOffsets[colIndex];
      var stickyClassName = stickyClassNames[colIndex];
      if (col.$$isOperation) {
        var node = col.node;
        var isExtraOperation = true;
        if (col.title === constant.INTERNAL_SELECTION_KEY) {
          node = (_b2 = bodyOperations.find(function(o) {
            return o.name === "selectionNode";
          })) === null || _b2 === void 0 ? void 0 : _b2.node;
          isExtraOperation = false;
        }
        if (col.title === constant.INTERNAL_EXPAND_KEY) {
          node = (_c2 = bodyOperations.find(function(o) {
            return o.name === "expandNode";
          })) === null || _c2 === void 0 ? void 0 : _c2.node;
          isExtraOperation = false;
        }
        var operationNode = typeof node === "function" ? node(record) : node;
        return React__default.default.cloneElement(operationNode, __assign(__assign({
          key: col.key || colIndex
        }, operationNode.props), {
          className: classNames(isExtraOperation ? operationClassName : "", (_d2 = operationNode === null || operationNode === void 0 ? void 0 : operationNode.props) === null || _d2 === void 0 ? void 0 : _d2.className, stickyClassName),
          style: __assign(__assign(__assign({}, (_e = operationNode === null || operationNode === void 0 ? void 0 : operationNode.props) === null || _e === void 0 ? void 0 : _e.style), col.fixed === "left" ? (_a2 = {}, _a2[rtl ? "right" : "left"] = stickyOffset, _a2) : {}), {
            width: col.width,
            minWidth: col.width
          })
        }));
      }
      return /* @__PURE__ */ emotionReactJsxRuntime_browser_esm.jsx(td, {
        prefixCls,
        virtualized,
        components,
        currentSorter,
        placeholder,
        indentSize,
        stickyClassName,
        stickyOffset,
        InnerComponentTd,
        column: col,
        columnIndex: colIndex,
        record,
        trIndex: index$3,
        level,
        haveTreeData,
        recordHaveChildren,
        rowKey: rowK,
        renderExpandIcon
      }, colIndex);
    })
  });
}
var ForwardRefTr = React.forwardRef(Tr);
const Tr$1 = ForwardRefTr;
module.exports = Tr$1;
//# sourceMappingURL=tr.js.map
