"use strict";
require("react");
const is = require("../../_util/is.js");
const classNames = require("../../_util/classNames.js");
const useComponent = require("../hooks/useComponent.js");
const index = require("../../_class/VirtualList/index.js");
const tr = require("./tr.js");
const utils = require("../utils.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");
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 TBody(props) {
  var _a = props.childrenColumnName, childrenColumnName = _a === void 0 ? "children" : _a, _b = props.expandProps, expandProps = _b === void 0 ? {} : _b, expandedRowRender = props.expandedRowRender, expandedRowKeys = props.expandedRowKeys, data = props.data, columns = props.columns, prefixCls = props.prefixCls, components = props.components, rowSelection = props.rowSelection, noDataElement = props.noDataElement, scroll = props.scroll, _c = props.indentSize, indentSize = _c === void 0 ? 16 : _c, hasFixedColumn = props.hasFixedColumn, tableViewWidth = props.tableViewWidth, virtualized = props.virtualized, getRowKey = props.getRowKey, saveVirtualWrapperRef = props.saveVirtualWrapperRef;
  var er = expandedRowRender ? function(r, i) {
    return expandedRowRender(utils.getOriginData(r), i);
  } : expandedRowRender;
  var ComponentTbody = useComponent(components).ComponentTbody;
  var type;
  if (rowSelection && "type" in rowSelection) {
    type = rowSelection.type;
  } else if (rowSelection && !("type" in rowSelection)) {
    type = "checkbox";
  }
  function isChildrenNotEmpty(record) {
    return is.isArray(record[childrenColumnName]) && record[childrenColumnName].length;
  }
  function shouldRowExpand(record, index2) {
    if ("rowExpandable" in expandProps && typeof expandProps.rowExpandable === "function") {
      return expandProps.rowExpandable(record);
    }
    return er && er(record, index2) !== null;
  }
  var trProps = __assign(__assign({}, props), {
    type,
    shouldRowExpand
  });
  function renderTreeTrs(record, index2) {
    var trList = [];
    trList.push(/* @__PURE__ */ emotionReactJsxRuntime_browser_esm.jsx(tr, {
      ...__assign({
        key: getRowKey(record)
      }, trProps, {
        record,
        level: 0,
        index: index2
      })
    }));
    var travel = function(children, rowKey, level) {
      if (level === void 0) {
        level = 0;
      }
      if (is.isArray(children) && children.length) {
        children.forEach(function(child, i) {
          if (expandedRowKeys.indexOf(rowKey) !== -1) {
            trList.push(/* @__PURE__ */ emotionReactJsxRuntime_browser_esm.jsx(tr, {
              ...__assign({}, trProps, {
                key: getRowKey(child),
                record: child,
                level: level + 1,
                index: i
              })
            }));
            if (isChildrenNotEmpty(child)) {
              travel(child[childrenColumnName], getRowKey(child), level + 1);
            }
          }
        });
      }
    };
    if (!er) {
      travel(record[childrenColumnName], getRowKey(record));
    }
    return trList;
  }
  var scrollStyleX = {};
  var scrollStyleY = {};
  if (scroll) {
    if (scroll.x && (typeof scroll.x === "number" || typeof scroll.x === "string")) {
      scrollStyleX = {
        width: scroll.x
      };
    }
    if (scroll.y && (typeof scroll.y === "number" || typeof scroll.y === "string")) {
      scrollStyleY = {
        maxHeight: scroll.y
      };
    }
  }
  var noElementProps = {
    className: prefixCls + "-no-data"
  };
  if (tableViewWidth) {
    noElementProps.className = prefixCls + "-no-data " + prefixCls + "-expand-fixed-row";
    noElementProps.style = {
      width: tableViewWidth
    };
  }
  var noDataTr = /* @__PURE__ */ emotionReactJsxRuntime_browser_esm.jsx("tr", {
    className: classNames(prefixCls + "-tr", prefixCls + "-empty-row"),
    children: /* @__PURE__ */ emotionReactJsxRuntime_browser_esm.jsx("td", {
      className: prefixCls + "-td",
      colSpan: columns.length,
      children: /* @__PURE__ */ emotionReactJsxRuntime_browser_esm.jsx("div", {
        ...__assign({}, noElementProps),
        children: noDataElement
      })
    })
  });
  if (virtualized) {
    return data.length > 0 ? /* @__PURE__ */ emotionReactJsxRuntime_browser_esm.jsx(index, {
      data,
      height: scrollStyleY.maxHeight,
      isStaticItemHeight: false,
      outerStyle: __assign(__assign({}, scrollStyleX), {
        minWidth: "100%",
        overflow: "visible"
      }),
      className: prefixCls + "-body",
      ref: function(ref) {
        return saveVirtualWrapperRef(ref === null || ref === void 0 ? void 0 : ref.dom);
      },
      children: function(child, index2) {
        return /* @__PURE__ */ emotionReactJsxRuntime_browser_esm.jsx(tr, {
          ...__assign({}, trProps, {
            key: getRowKey(child),
            record: child,
            index: index2,
            level: 0
          })
        });
      }
    }) : /* @__PURE__ */ emotionReactJsxRuntime_browser_esm.jsx("div", {
      className: prefixCls + "-body",
      children: /* @__PURE__ */ emotionReactJsxRuntime_browser_esm.jsx("table", {
        children: /* @__PURE__ */ emotionReactJsxRuntime_browser_esm.jsx("tbody", {
          children: noDataTr
        })
      })
    });
  }
  return /* @__PURE__ */ emotionReactJsxRuntime_browser_esm.jsx(ComponentTbody, {
    children: data.length > 0 ? data.map(function(record, index2) {
      var rowK = getRowKey(record);
      var shouldRenderExpandIcon = shouldRowExpand(record, index2) && expandedRowKeys.indexOf(rowK) !== -1;
      return /* @__PURE__ */ emotionReactJsxRuntime_browser_esm.jsxs(emotionReactJsxRuntime_browser_esm.Fragment, {
        children: [renderTreeTrs(record, index2), shouldRenderExpandIcon && /* @__PURE__ */ emotionReactJsxRuntime_browser_esm.jsx("tr", {
          className: classNames(prefixCls + "-tr", prefixCls + "-expand-content"),
          children: /* @__PURE__ */ emotionReactJsxRuntime_browser_esm.jsx("td", {
            className: prefixCls + "-td",
            colSpan: columns.length,
            style: {
              paddingLeft: indentSize
            },
            children: hasFixedColumn ? /* @__PURE__ */ emotionReactJsxRuntime_browser_esm.jsx("div", {
              className: prefixCls + "-expand-fixed-row",
              style: {
                width: tableViewWidth
              },
              children: er && er(record, index2)
            }) : er && er(record, index2)
          })
        }, rowK + "-expanded")]
      });
    }) : noDataTr
  });
}
module.exports = TBody;
//# sourceMappingURL=index.js.map
