import{slicedToArray as r}from"../../_virtual/_rollupPluginBabelHelpers.js";import{jsx as e}from"react/jsx-runtime";import{forwardRef as t,useState as n,useRef as o,useCallback as i,useMemo as l,useEffect as u}from"react";import c from"classnames";import{VariableSizeGrid as s}from"react-window";import a from"react-virtualized-auto-sizer";import{getNormalizedItems as d,getOnItemsRenderedData as f,isLayoutDirectionScrollbarVisible as m}from"../../services/virtualized-service.js";import v from"../../hooks/usePrevious/index.js";import h from"../../hooks/useThrottledCallback.js";import g from"../../hooks/useMergeRefs.js";import{NOOP as p}from"../../utils/function-utils.js";import"./VirtualizedGrid.scss.js";var I=t((function(t,I){var w=t.className,x=t.id,b=t.items,j=void 0===b?[]:b,S=t.itemRenderer,T=void 0===S?function(r,e,t){return r}:S,z=t.getRowHeight,C=void 0===z?function(){return 50}:z,R=t.getColumnWidth,M=void 0===R?function(){return 100}:R,N=t.getItemId,O=void 0===N?function(r,e){return r.id}:N,k=t.onScroll,y=t.scrollToId,H=void 0===y?null:y,V=t.onScrollToFinished,W=void 0===V?p:V,A=t.onItemsRendered,F=void 0===A?null:A,P=t.onItemsRenderedThrottleMs,U=void 0===P?200:P,_=t.onSizeUpdate,q=void 0===_?p:_,B=t.onVerticalScrollbarVisiblityChange,D=void 0===B?null:B,G=n(0),E=r(G,2),J=E[0],K=E[1],L=n(0),Q=r(L,2),X=Q[0],Y=Q[1],Z=v(H),$=o(null),rr=o(null),er=o(null),tr=o(0),nr=o({scrollOffsetInitial:0,scrollOffsetFinal:0,animationStartTime:0}),or=g({refs:[I,$]}),ir=nr.current,lr=i((function(r){var e=C();return e&&!Number.isNaN(e)||console.error("Couldn't get height for item: ",r),e}),[C]),ur=i((function(r,e){var t=O(r,e);return void 0===t&&console.error("Couldn't get id for item: ",r),t}),[O]),cr=l((function(){return d(j,ur,lr)}),[j,ur,lr]),sr=l((function(){return Math.min(j.length,Math.floor(X/M()))}),[j,X,M]),ar=l((function(){return sr>0?Math.ceil(j.length/sr):0}),[j,sr]),dr=l((function(){return H%sr}),[H,sr]),fr=l((function(){return Math.floor(H/sr)}),[H,sr]),mr=i((function(r){var e=r.horizontalScrollDirection,t=r.scrollTop,n=r.scrollUpdateWasRequested;tr.current=t,n||(ir.scrollOffsetInitial=t),k&&k(e,t,n)}),[k,tr,ir]),vr=i((function(r){var e=r.rowIndex*sr+r.columnIndex;return T(j[e],e,r.style)}),[j,T,sr]),hr=i((function(r,e){e===J&&r===X||setTimeout((function(){K(e),Y(r),q(r,e)}),0)}),[J,X,q]),gr=h((function(r){if(F){var e=f(j,cr,ur,r.visibleStartIndex,r.visibleStopIndex,J,tr.current);F(e)}}),{wait:U,trailing:!0},[F,j,cr,ur,J]);return u((function(){H&&Z!==H&&(er.current.scrollToItem({align:"center",columnIndex:dr,rowIndex:fr}),W())}),[H,Z,er,dr,fr,W]),u((function(){er.current&&er.current.resetAfterIndices({columnIndex:0,rowIndex:0})}),[cr]),u((function(){if(D){var r=m(j,cr,ur,J);rr.current!==r&&(rr.current=r,D(r))}}),[D,j,cr,J,ur]),e("div",Object.assign({ref:or,className:c("virtualized-grid--wrapper",w),id:x},{children:e(a,{children:function(r){var t=r.height,n=r.width;return hr(n,t),e(s,Object.assign({ref:er,height:t,width:n,columnWidth:M,columnCount:sr,rowHeight:C,rowCount:ar,onScroll:mr,onItemsRendered:gr,className:"virtualized-grid-scrollable-container"},{children:vr}))}})}))}));export{I as default};
