import _extends from "@babel/runtime/helpers/extends";
import React, { useContext } from 'react';
import { observer } from 'mobx-react-lite';
import { useInView } from 'react-intersection-observer';
import { pxToRem } from '../../../es/_util/UnitConvertor';
import TableContext from './TableContext';
import { VIRTUAL_ROOT_MARGIN } from './TableStore';
import TableCell from './TableCell';

var TableVirtualCell = function TableVirtualCell(props) {
  var _useContext = useContext(TableContext),
      node = _useContext.tableStore.node;

  var _useInView = useInView({
    root: node.tableBodyWrap || node.element,
    rootMargin: "".concat(VIRTUAL_ROOT_MARGIN, "px"),
    initialInView: true
  }),
      intersectionRef = _useInView.ref,
      inView = _useInView.inView,
      entry = _useInView.entry;

  var height = !inView && entry && entry.target.offsetParent ? pxToRem(entry.boundingClientRect.height || entry.target.offsetHeight, true) : undefined;
  return /*#__PURE__*/React.createElement(TableCell, _extends({}, props, {
    intersectionRef: intersectionRef,
    inView: inView,
    virtualHeight: height
  }));
};

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