import r from"@babel/runtime/helpers/slicedToArray";import{jsxs as i,jsx as t}from"react/jsx-runtime";import{useState as e,useMemo as n,useRef as a,useEffect as u}from"react";import{InputLabel as o,TextField as s}from"@material-ui/core";import{debounce as l}from"lodash";import m from"classnames";import{getIsImperial as c}from"../../../../../utils/getIsImperial.js";import d from"./RadiusInput.module.css.js";import{convertValue as f}from"../../../../../../../utils/index.js";var p=function(p){var v=p.radius,b=p.editable,h=p.isLassoActive,g=void 0!==h&&h,N=p.isSatellite,I=void 0!==N&&N,j=p.onChange,k=p["data-testid"],x=void 0===k?"RadiusInput":k,F=p.className,R=e(""),S=r(R,2),y=S[0],A=S[1],C=e(!1),E=r(C,2),B=E[0],L=E[1],P=e(!1),T=r(P,2),U=T[0],_=T[1],q=n((function(){return c()}),[]),w=n((function(){return l((function(r){return j(r)}),1500)}),[j]),z=a(w);z.current=w,u((function(){return function(){return z.current.cancel()}}),[]),u((function(){if(!U){var r=q?v:f(v,"length","mi","km",3);A(function(r){return Number.isInteger(r)?String(r):r.toFixed(2)}(Number(r)))}}),[q,v,U]);var D=q?"mi":"km",G=!b||g;return i("div",{className:m(d.radiusInput,I&&d.satellite,G&&d.disabled,F),children:[i(o,{htmlFor:"radius-input",className:d.label,children:["Radius (",D,"):"]}),t(s,{id:"radius-input","data-testid":"".concat(x,"_input"),type:"number",value:y,disabled:G,onChange:function(r){if(!(t=null===(i=r.nativeEvent)||void 0===i?void 0:i.data)||!["e","E","+","-"].includes(t)){var i,t,e=r.target.value;A(e);var n=function(r){if(""===r)return!0;var i=Number(r);return Number.isFinite(i)&&i>=0}(e);if(L(!n),n&&""!==e){var a=q?+e:f(+e,"length","km","mi",3);w(Number(a))}}},onFocus:function(){return _(!0)},onBlur:function(){z.current.flush(),_(!1)},error:B,className:d.field,"aria-label":"Radius in ".concat(q?"miles":"kilometers"),"aria-invalid":B,inputProps:{lang:"en-US"}})]})};export{p as RadiusInput};
//# sourceMappingURL=RadiusInput.js.map
