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