import _toConsumableArray from"@babel/runtime/helpers/toConsumableArray";import{useCallback,useEffect}from"react";import{getElementSize}from"../useComponentSize";export var defaultItemsCalculationCount=5;var visualGap=200;export var useScroll=function(a,b,c){useEffect(function(){return c?b():void 0},[a.current,b,c]),useEffect(function(){if(c){var d;null===(d=a.current)||void 0===d?void 0:d.addEventListener("scroll",b)}return function(){var c;null===(c=a.current)||void 0===c?void 0:c.removeEventListener("scroll",b)}},[a.current,b,c])};export var getElementHeight=function(a){return getElementSize(a).height};var roundPositionByGap=function(a,b){return 0>=a?0:Math.ceil(a/b)*b};export var getVisiblePosition=function(a,b){var c=Math.ceil(roundPositionByGap(0>a-b?0:a-b,b)-visualGap);return[0>=c?0:c,Math.ceil(roundPositionByGap(0===a?b:a,b)+b+visualGap)]};export var calculateSavedSizes=function(a,b){for(var c,d=_toConsumableArray(a),e=0;e<b.length;e++)c=b[e],0<c&&(d[e]=c);return d};export var useCalculateVisiblePosition=function(a,b){return useCallback(function(){if(a){var c=getVisiblePosition(a.scrollTop,getElementHeight(a));b(function(a){return c[0]!==a[0]||c[1]!==a[1]?c:a})}},[a,b])};var addCount=function(a,b,c){for(var d=c.slice(-50),e=d.reduce(function(c,a){return c+a},0)/d.length,f=defaultItemsCalculationCount;b[1]>a[1]+f*e;)f+=defaultItemsCalculationCount;return f};export var calculateBounds=function(a,b,c,d){for(var e=[0,0],f=[0,0],g=0;g<a.length;g++)c[0]>e[0]&&(e[0]+=a[g],f[0]=g),c[1]>e[1]&&(e[1]+=a[g],f[1]=g);return 0===f[0]&&0===f[1]&&(f[1]=defaultItemsCalculationCount),a.length-1>=f[1]&&b.length!==a.length&&(f[1]+=addCount(e,c,a)),f[1]-1>d&&(f[1]=d-1),[e,f]};
//# sourceMappingURL=hellpers.js.map