import e from"@babel/runtime/helpers/defineProperty";import i from"@babel/runtime/helpers/slicedToArray";import{useState as t,useEffect as n,useCallback as o}from"react";import{isEmpty as r,debounce as s}from"lodash";import{getXExtremes as a,getYExtremes as m,getChartScale as p,getNextZoomCoordinates as x,getIsMaxZoom as c,getCurrentMinValue as l,getCurrentMaxValue as f}from"../utils.js";import{MAX_ZOOM as g}from"../constants.js";function u(e,i){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);i&&(n=n.filter((function(i){return Object.getOwnPropertyDescriptor(e,i).enumerable}))),t.push.apply(t,n)}return t}function M(i){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?u(Object(n),!0).forEach((function(t){e(i,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(i,Object.getOwnPropertyDescriptors(n)):u(Object(n)).forEach((function(e){Object.defineProperty(i,e,Object.getOwnPropertyDescriptor(n,e))}))}return i}var y=function(e){var u=e.chart,y=t({}),b=i(y,2),O=b[0],S=b[1],h=t(!0),j=i(h,2),d=j[0],v=j[1],z=t({isReset:!0,isMax:!1}),E=i(z,2),P=E[0],X=E[1];n((function(){if(!r(u)){var e=u.xAxis,i=u.yAxis,t=null!=e&&e.length?e[0]:{},n=t.min,o=t.max,s=null!=i&&i.length?i[0]:{},a=s.min,m=s.max;S({xStep:(o-n)/g,yStep:(m-a)/g,originXMin:n,originXMax:o,originYMin:a,originYMax:m,isMaxZoom:!1,isZoomReset:!0})}}),[u]);return{zoomStatus:P,debouncedChartSelection:o(s((function(){X((function(e){return M(M({},e),{},{isReset:!1})}))}),500),[u]),isZoomEnabled:d,handleIsZoomEnabledChange:function(e){v(e)},handleResetZoom:function(){var e=O.originXMin,i=O.originXMax,t=O.originYMin,n=O.originYMax;u.xAxis[0].setExtremes(e,i),u.yAxis[0].setExtremes(t,n),v(!0),X({isReset:!0,isMax:!1})},handleZoomEvent:function(e){var t=a(u),n=m(u),o=p({extremes:t,step:O.xStep}),r=p({extremes:n,step:O.yStep}),s=x({min:t.min,max:t.max,initialMin:O.originXMin,initialMax:O.originXMax,zoomStep:O.xStep,zoomType:e,scale:o}),g=x({min:n.min,max:n.max,initialMin:O.originYMin,initialMax:O.originYMax,zoomStep:O.yStep,zoomType:e,scale:r}),M=i(s,2),y=M[0],b=M[1],S=i(g,2),h=S[0],j=S[1],d=O.originXMin,z=O.originXMax,E=O.originYMax,P=O.originYMin,Y=l(y,d),A=l(h,P),w=f(b,z),R=f(j,E),Z=c({min:y,max:b,zoomStep:O.xStep,zoomType:e}),T=c({min:y,max:b,zoomStep:O.xStep,zoomType:e}),D=d===Y&&z===w&&E===R&&P===A;u.xAxis[0].setExtremes(Y>b?b:Y,w<y?y:w),u.yAxis[0].setExtremes(A>j?j:A,R<h?h:R),X({isReset:D,isMax:Z&&T}),D&&v(!0)},zoomConfig:O}};export{y as useZoom};
