import _objectSpread from "@babel/runtime/helpers/objectSpread2";
import React, { useContext } from 'react';
import { observer } from 'mobx-react-lite';
import { pxToRem } from '../../../es/_util/UnitConvertor';
import measureScrollbar from '../../../es/_util/measureScrollbar';
import TableContext from './TableContext';
import { ColumnLock } from './enum';

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

  var _useContext = useContext(TableContext),
      prefixCls = _useContext.prefixCls,
      tableStore = _useContext.tableStore;

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

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

  return tableBody;
};

TableBody.displayName = 'TableBody';
export default observer(TableBody);
//# sourceMappingURL=TableBody.js.map
