"use strict";

var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard")["default"];

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = void 0;

var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));

var _react = _interopRequireWildcard(require("react"));

var _mobxReactLite = require("mobx-react-lite");

var _UnitConvertor = require("../../../lib/_util/UnitConvertor");

var _measureScrollbar = _interopRequireDefault(require("../../../lib/_util/measureScrollbar"));

var _TableContext = _interopRequireDefault(require("./TableContext"));

var _enum = require("./enum");

var TableBody = function TableBody(props) {
  var children = props.children,
      lock = props.lock,
      onScroll = props.onScroll,
      style = props.style,
      getRef = props.getRef;

  var _useContext = (0, _react.useContext)(_TableContext["default"]),
      prefixCls = _useContext.prefixCls,
      tableStore = _useContext.tableStore;

  var hasFooter = tableStore.hasFooter,
      overflowY = tableStore.overflowY,
      overflowX = tableStore.overflowX,
      height = tableStore.height;
  var fixedLeft = lock === true || lock === _enum.ColumnLock.left;
  var scrollbar = (0, _measureScrollbar["default"])();
  var hasFooterAndNotLock = !lock && hasFooter && overflowX && scrollbar;
  var hasLockAndNoFooter = lock && !hasFooter && overflowX && height !== undefined && scrollbar;

  var tableBody = /*#__PURE__*/_react["default"].createElement("div", {
    ref: getRef,
    className: "".concat(prefixCls, "-body"),
    style: (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, height === undefined ? style : {}), {}, {
      height: (0, _UnitConvertor.pxToRem)(hasFooterAndNotLock && height !== undefined ? height + scrollbar : hasLockAndNoFooter && height !== undefined ? height - scrollbar : height, true),
      marginBottom: hasFooterAndNotLock ? (0, _UnitConvertor.pxToRem)(-scrollbar, true) : undefined,
      width: fixedLeft ? (0, _UnitConvertor.pxToRem)(tableStore.leftColumnGroups.width + (scrollbar || 20), true) : lock === _enum.ColumnLock.right ? (0, _UnitConvertor.pxToRem)(tableStore.rightColumnGroups.width - 1 + (overflowY ? scrollbar : 0), true) : undefined,
      marginLeft: lock === _enum.ColumnLock.right ? (0, _UnitConvertor.pxToRem)(1) : undefined
    }),
    onScroll: onScroll
  }, children);

  if (fixedLeft) {
    return /*#__PURE__*/_react["default"].createElement("div", {
      className: "".concat(prefixCls, "-body-wrapper"),
      style: {
        width: (0, _UnitConvertor.pxToRem)(tableStore.leftColumnGroups.width, true)
      }
    }, tableBody);
  }

  return tableBody;
};

TableBody.displayName = 'TableBody';

var _default = (0, _mobxReactLite.observer)(TableBody);

exports["default"] = _default;
//# sourceMappingURL=TableBody.js.map
