"use strict";

exports.__esModule = true;
exports.VirtualTableRowMutated = VirtualTableRowMutated;
var _react = require("react");
var _VirtualGridStateContext = require("./VirtualGridStateContext");
var _VirtualTableRowMutatedState = require("./VirtualTableRowMutatedState");
function VirtualTableRowMutated(props) {
  const {
    children,
    index,
    style,
    itemKey,
    rowIndex
  } = props;
  const gridState = (0, _VirtualGridStateContext.useVirtualGridStateContext)();
  const element = children[index];
  const rowRef = (0, _react.useRef)();
  const [state] = (0, _react.useState)(() => new _VirtualTableRowMutatedState.VirtualTableRowMutatedState({
    rowRef,
    state: gridState,
    itemKey,
    index,
    rowIndex
  }));
  (0, _react.useEffect)(() => {
    state.index = index;
  }, [index]);
  (0, _react.useEffect)(() => {
    state.rowIndex = rowIndex;
  }, [rowIndex]);
  (0, _react.useEffect)(() => {
    state.itemKey = itemKey;
  }, [itemKey]);
  (0, _react.useEffect)(() => {
    state._measureRowContentsHeight();
  }, [rowRef, rowIndex]);
  (0, _react.useEffect)(() => state.init(), []);
  const ref = (0, _react.useCallback)(el => {
    rowRef.current = el;
  }, []);
  if (element == null) {
    return null;
  }
  return /*#__PURE__*/(0, _react.cloneElement)(element, {
    style: {
      ...(element.props.style ?? {}),
      ...style
    },
    rowProps: {
      ...(element.props.rowProps ?? {}),
      'data-key': process.env.NODE_ENV === 'development' ? itemKey == null ? void 0 : itemKey(index) : undefined,
      'data-index': `index-${index}`,
      ref
    }
  });
}
//# sourceMappingURL=VirtualTableRowMutated.js.map