"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports.ForceRenderIndexesObserver = void 0;
var _react = _interopRequireDefault(require("react"));
var _VirtualGridRepeaterContext = require("./VirtualGridRepeaterContext");
var _mobxReactLite = require("mobx-react-lite");
var _jsxFileName = "/home/builduser/work/843658b9f44192f0/packages/cairo/dist/cjs/components/VirtualGridRepeater/ForceRenderIndexes.tsx";
function _ForceRenderIndexes({
  children,
  ItemElementType,
  contentsWrapper
}) {
  var _forceRenderIndexes$f;
  const {
    state
  } = (0, _VirtualGridRepeaterContext.useVirtualGridRepeaterContext)();
  const {
    gridState: {
      forceRenderIndexes,
      listAttributes,
      itemsToRenderCount
    },
    gridRef,
    calcGridProps: {
      columnCount
    }
  } = state;
  if (process.env.NODE_ENV !== 'production') {
    if (gridRef) {
      if (typeof gridRef._getItemStyle !== 'function') {
        throw new Error('Missing `_getItemStyle()` API from react-window. This is probably a breaking change of react-window, please contact #cairo, thanks!');
      }
    }
  }
  const forceRenderElements = gridRef && (forceRenderIndexes == null || (_forceRenderIndexes$f = forceRenderIndexes.filter(index => index < itemsToRenderCount)) == null ? void 0 : _forceRenderIndexes$f.map(index => {
    const rowIndex = Math.floor(index / columnCount);
    const columnIndex = index % columnCount;
    const key = state.itemKeyRecycler({
      columnIndex,
      rowIndex
    });
    return /*#__PURE__*/_react.default.createElement(ItemElementType, {
      key: key,
      rowIndex: rowIndex,
      columnIndex: columnIndex,
      style: gridRef._getItemStyle(rowIndex, columnIndex),
      data: undefined,
      __self: this,
      __source: {
        fileName: _jsxFileName,
        lineNumber: 47,
        columnNumber: 11
      }
    });
  }));
  const contents = /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, forceRenderElements, forceRenderElements ? children.filter(({
    props
  }) => !forceRenderElements.some(({
    props: {
      rowIndex,
      columnIndex
    }
  }) => rowIndex === props.rowIndex && columnIndex === props.columnIndex)) : children);
  return contentsWrapper({
    contents,
    listAttributes
  });
}
const ForceRenderIndexesObserver = exports.ForceRenderIndexesObserver = (0, _mobxReactLite.observer)(_ForceRenderIndexes);
//# sourceMappingURL=ForceRenderIndexes.js.map