import React__default, { memo, useContext } from "react";
import get_1 from "../../../../../../../lodash@4.17.21/node_modules/lodash/get.js";
import pick from "../../_util/pick.js";
import { isObject, isString } from "../../_util/is.js";
import cs from "../../_util/classNames.js";
import useComponent from "../hooks/useComponent.js";
import { getOriginData } from "../utils.js";
import { ConfigContext } from "../../ConfigProvider/index.js";
import { jsxs, jsx, Fragment } from "../../../../../../../@emotion_react@11.10.4_3toe27fv7etiytxb5kxc7fxaw4/node_modules/@emotion/react/jsx-runtime/dist/emotion-react-jsx-runtime.browser.esm.js";
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 isInvalidRenderElement(element) {
  return element && !React__default.isValidElement(element) && isObject(element);
}
function Td(props) {
  var _a, _b;
  var components = props.components, InnerComponentTd = props.InnerComponentTd, column = props.column, columnIndex = props.columnIndex, prefixCls = props.prefixCls, stickyClassName = props.stickyClassName, stickyOffset = props.stickyOffset, currentSorter = props.currentSorter, virtualized = props.virtualized, record = props.record, trIndex = props.trIndex, level = props.level, placeholder = props.placeholder, indentSize = props.indentSize, renderExpandIcon = props.renderExpandIcon, rowKey = props.rowKey, recordHaveChildren = props.recordHaveChildren, haveTreeData = props.haveTreeData;
  var rtl = useContext(ConfigContext).rtl;
  var ComponentBodyCell = useComponent(components).ComponentBodyCell;
  var classNameTd = cs(prefixCls + "-td", stickyClassName, (_a = {}, _a[prefixCls + "-col-sorted"] = currentSorter && currentSorter.direction && currentSorter.field === column.dataIndex, _a), column.className);
  var tdProps = {};
  var rowSpan;
  var colSpan;
  var styleTd = {};
  if (column.fixed === "left") {
    styleTd[rtl ? "right" : "left"] = stickyOffset;
  }
  if (column.fixed === "right") {
    styleTd[rtl ? "left" : "right"] = stickyOffset;
  }
  if (isObject(column.cellStyle)) {
    styleTd = __assign(__assign({}, styleTd), column.cellStyle);
  }
  if (isObject(column.bodyCellStyle)) {
    styleTd = __assign(__assign({}, styleTd), column.bodyCellStyle);
  }
  if (column.align) {
    styleTd.textAlign = column.align;
  }
  if (virtualized && column.width) {
    styleTd.width = column.width;
    styleTd.minWidth = column.width;
    styleTd.maxWidth = column.width;
  }
  var _c = column.onCell ? column.onCell(record, trIndex) : {
    onHandleSave: function() {
    }
  }, onHandleSave = _c.onHandleSave, cellProps = __rest(_c, ["onHandleSave"]);
  var renderElement = column.render && column.render(get_1(record, column.dataIndex), getOriginData(record), trIndex);
  if (isInvalidRenderElement(renderElement)) {
    tdProps = renderElement.props;
    rowSpan = tdProps.rowSpan;
    colSpan = tdProps.colSpan;
    renderElement = renderElement.children;
  }
  if (rowSpan === 0 || colSpan === 0) {
    return null;
  }
  var v = get_1(record, column.dataIndex);
  var cellChildren = column.render ? renderElement : v === void 0 || typeof v === "string" && v.trim() === "" || v === null ? column.placeholder === void 0 ? placeholder : column.placeholder : v;
  var titleProps = column.ellipsis && typeof cellChildren === "string" ? {
    title: cellChildren
  } : {};
  var hasInlineExpandIcon = haveTreeData && column.$$isFirstColumn;
  var needRenderExpandIcon = hasInlineExpandIcon && recordHaveChildren;
  var paddingLeft = hasInlineExpandIcon && level > 0 ? indentSize * level : 0;
  if (hasInlineExpandIcon && !recordHaveChildren) {
    paddingLeft += 16 + 4;
  }
  var content = /* @__PURE__ */ jsxs(Fragment, {
    children: [needRenderExpandIcon ? /* @__PURE__ */ jsx("span", {
      className: prefixCls + "-cell-expand-icon",
      children: renderExpandIcon(record, rowKey)
    }) : null, isString(ComponentBodyCell) ? /* @__PURE__ */ jsx(ComponentBodyCell, {
      className: prefixCls + "-cell-wrap-value",
      children: cellChildren
    }) : /* @__PURE__ */ jsx(ComponentBodyCell, {
      ...__assign({
        rowData: record,
        className: prefixCls + "-cell-wrap-value",
        column,
        onHandleSave
      }, cellProps),
      children: cellChildren
    })]
  });
  return /* @__PURE__ */ jsx(InnerComponentTd, {
    ...__assign({
      className: classNameTd,
      key: column.key || column.dataIndex || columnIndex,
      style: styleTd
    }, pick(cellProps, ["onClick", "onDoubleClick", "onContextMenu", "onMouseOver", "onMouseEnter", "onMouseLeave", "onMouseMove", "onMouseDown", "onMouseUp"]), tdProps),
    children: /* @__PURE__ */ jsxs("div", {
      ...__assign({
        className: cs(prefixCls + "-cell", (_b = {}, _b[prefixCls + "-cell-text-ellipsis"] = column.ellipsis, _b))
      }, titleProps),
      children: [paddingLeft ? /* @__PURE__ */ jsx("span", {
        className: prefixCls + "-cell-indent",
        style: {
          paddingLeft
        }
      }) : null, content]
    })
  });
}
const Td$1 = memo(Td);
export {
  Td$1 as default
};
//# sourceMappingURL=td.js.map
