"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@babel/runtime/helpers/defineProperty"),t=require("@babel/runtime/helpers/slicedToArray"),n=require("react"),o=require("geolib"),r=require("lodash/isEqual"),u=require("lodash/throttle"),a=require("../../../../utils/getIsImperial.js"),i=require("../constants.js"),l=require("../../../../../../utils/convert.js");function c(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var f=c(e),s=c(t),d=c(r),m=c(u);function p(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);t&&(o=o.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,o)}return n}function g(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?p(Object(n),!0).forEach((function(t){f.default(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):p(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}var v=function(e){return Math.min(Math.max(e,i.MapConfig.Zoom.Min),i.MapConfig.Zoom.Max)},b=function(e,t){var n=e.getCanvas(),r=n.clientHeight/2,u=n.clientWidth/2,a=e.unproject([u-33,r]),i=e.unproject([u+33,r]);return function(e,t){if(t){var n=l.convertValue(e,"length","m","ft");if(n>=5280){var o=l.convertValue(e,"length","m","mi");return"".concat(o.toFixed(o<10?1:0),"mi")}return"".concat(Math.round(n),"ft")}if(e>=1e3){var r=l.convertValue(e,"length","m","km");return"".concat(r.toFixed(r<10?1:0),"km")}return"".concat(Math.round(e),"m")}(o.getDistance({latitude:a.lat,longitude:a.lng},{latitude:i.lat,longitude:i.lng}),t)};exports.BAR_WIDTH_PX=66,exports.useMapViewState=function(e,t){var o,r,u=n.useState({longitude:null!==(o=null==t?void 0:t.longitude)&&void 0!==o?o:i.MapConfig.DefaultCoords.longitude,latitude:null!==(r=null==t?void 0:t.latitude)&&void 0!==r?r:i.MapConfig.DefaultCoords.latitude,zoom:i.MapConfig.Zoom.Initial}),l=s.default(u,2),c=l[0],f=l[1],p=n.useState(null),h=s.default(p,2),M=h[0],O=h[1],j=function(e,t){var o=n.useCallback((function(){var n=e.current;return n?b(n,t):null}),[e,t]),r=n.useRef(o);r.current=o;var u=n.useRef(m.default((function(){return r.current()}),100,{trailing:!0})).current;return n.useEffect((function(){return function(){u.cancel()}}),[u]),{calculateDistanceNow:o,throttledUpdate:u}}(e,n.useMemo((function(){return a.getIsImperial()}),[])),C=j.calculateDistanceNow,y=j.throttledUpdate,w=n.useCallback((function(){y();var e=C();null!==e&&O(e)}),[y,C]);return{viewState:c,distance:M,handleMove:n.useCallback((function(e){var t=e.viewState,n=t.longitude,o=t.latitude,r=t.zoom,u={longitude:n,latitude:o,zoom:v(r)};f((function(e){return d.default(e,u)?e:u})),w()}),[w]),handleZoomIn:n.useCallback((function(){f((function(e){return e.zoom>=i.MapConfig.Zoom.Max?e:g(g({},e),{},{zoom:v(e.zoom+1)})})),w()}),[w]),handleZoomOut:n.useCallback((function(){f((function(e){return e.zoom<=i.MapConfig.Zoom.Min?e:g(g({},e),{},{zoom:v(e.zoom-1)})})),w()}),[w]),canZoomIn:c.zoom<i.MapConfig.Zoom.Max,canZoomOut:c.zoom>i.MapConfig.Zoom.Min}};
//# sourceMappingURL=useMapViewState.js.map
