"use strict";

exports.__esModule = true;
exports.VirtualGridRepeaterBase = void 0;
var _react = _interopRequireWildcard(require("react"));
var _mobxReactLite = require("mobx-react-lite");
var _reactWindow = require("react-window");
var _providers = require("../../providers");
var _VirtualGridRepeaterState = require("./VirtualGridRepeaterState");
var _VirtualGridRepeaterContext = require("./VirtualGridRepeaterContext");
var _jsxFileName = "/home/builduser/work/843658b9f44192f0/packages/cairo/dist/cjs/components/VirtualGridRepeater/VirtualGridRepeaterBase.tsx";
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
function _VirtualGridRepeaterBase(props) {
  const {
    gridState,
    renderItem,
    innerElementType,
    outerElementType,
    children
  } = props;
  const {
    scrollableContentRef
  } = (0, _providers.useScrollableContentContext)();
  const [state] = (0, _react.useState)(() => new _VirtualGridRepeaterState.VirtualGridRepeaterState({
    gridState
  }));
  const {
    calcGridProps,
    rowCount,
    height,
    width,
    itemKeyRecycler: itemKey
  } = state;
  const [onFullRenderEnd] = (0, _react.useState)(() => state.gridState.toolbar.fedopsReporter.onFullRenderStart == null ? void 0 : state.gridState.toolbar.fedopsReporter.onFullRenderStart());
  (0, _react.useEffect)(() => {
    if (height && width) {
      onFullRenderEnd == null || onFullRenderEnd();
    }
  }, [height && width]);
  const {
    columnCount,
    columnWidthIncludingGap,
    rowHeightIncludingGap,
    overscanCount,
    estimatedRowHeight
  } = calcGridProps;
  (0, _react.useEffect)(() => {
    const container = scrollableContentRef == null ? void 0 : scrollableContentRef.current;
    return state.init({
      container
    });
  }, []);
  const style = (0, _react.useMemo)(() => ({
    overflow: 'visible',
    height: '100%'
  }), []);
  const context = (0, _react.useMemo)(() => ({
    state,
    renderItem,
    itemKey
  }), [renderItem, itemKey]);
  (0, _react.useEffect)(() => {
    var _state$gridRef;
    (_state$gridRef = state.gridRef) == null || _state$gridRef.resetAfterIndices({
      columnIndex: 0,
      rowIndex: 0,
      shouldForceUpdate: true
    });
  }, [height, width, calcGridProps]);
  return /*#__PURE__*/_react.default.createElement(_VirtualGridRepeaterContext.VirtualGridRepeaterContextProvider, {
    value: context,
    __self: this,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 95,
      columnNumber: 5
    }
  }, /*#__PURE__*/_react.default.createElement(_reactWindow.VariableSizeGrid, {
    ref: el => {
      state.gridRef = el;
      state.gridState.gridRef = el;
    },
    height: height,
    width: width,
    columnCount: columnCount,
    outerElementType: outerElementType,
    innerElementType: innerElementType,
    columnWidth: () => columnWidthIncludingGap(0),
    rowHeight: index => rowHeightIncludingGap({
      index,
      key: itemKey({
        rowIndex: index,
        columnIndex: 0
      })
    }) ?? estimatedRowHeight,
    estimatedRowHeight: estimatedRowHeight,
    rowCount: height && width ? rowCount : 0,
    overscanRowCount: overscanCount,
    itemKey: itemKey,
    style: style,
    __self: this,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 96,
      columnNumber: 7
    }
  }, children));
}
const VirtualGridRepeaterBase = exports.VirtualGridRepeaterBase = (0, _mobxReactLite.observer)(_VirtualGridRepeaterBase);
//# sourceMappingURL=VirtualGridRepeaterBase.js.map