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