import _objectWithoutProperties from"@babel/runtime/helpers/objectWithoutProperties";var _excluded=["className","value","defaultValue","onChange","id","name","inputRef","maxLength","disabled","size","view","form","status","onBlur","onFocus","autoFocus","placeholder","leftSide","rightSide","autoComplete","withClearButton","readOnly","type","tabIndex","ariaLabel","iconSize","onClick","incrementButtons","max","min","step","onKeyDown","onKeyDownCapture","onKeyUp","onKeyUpCapture","onCopy","onCopyCapture","onCut","onCutCapture","onPaste","onPasteCapture","onClear"];import React,{forwardRef,useCallback,useMemo}from"react";import{FieldClearButton,FieldControlLayout,FieldCounter,FieldInput,renderSide}from"../../FieldComponents";import{useForkRef}from"../../../hooks/useForkRef";import{useKeys}from"../../../hooks/useKeys";import{useMutableRef}from"../../../hooks/useMutableRef/useMutableRef";import{useSortSteps}from"../../../hooks/useSortSteps";import{useTextField}from"../useTextField";import{cnTextFieldTypeNumber}from"./cnTextFieldTypeNumber";import{getValueByStep,stepIsActive}from"./helpers";export var TextFieldTypeNumber=forwardRef(function(a,b){var c=a.className,d=a.value,e=a.defaultValue,f=a.onChange,g=a.id,h=a.name,i=a.inputRef,j=a.maxLength,k=a.disabled,l=a.size,m=void 0===l?"m":l,n=a.view,o=void 0===n?"default":n,p=a.form,q=a.status,r=a.onBlur,s=a.onFocus,t=a.autoFocus,u=a.placeholder,v=a.leftSide,w=a.rightSide,x=a.autoComplete,y=a.withClearButton,z=a.readOnly,A=a.type,B=a.tabIndex,C=a.ariaLabel,D=a.iconSize,E=a.onClick,F=a.incrementButtons,G=a.max,H=a.min,I=a.step,J=a.onKeyDown,K=a.onKeyDownCapture,L=a.onKeyUp,M=a.onKeyUpCapture,N=a.onCopy,O=a.onCopyCapture,P=a.onCut,Q=a.onCutCapture,R=a.onPaste,S=a.onPasteCapture,T=a.onClear,U=_objectWithoutProperties(a,_excluded),V=useTextField({onClick:E,onChange:f,onBlur:r,onFocus:s,disabled:k,onClear:T}),W=V.handleBlur,X=V.handleChange,Y=V.handleClear,Z=V.handleFocus,$=V.focused,_=V.withValue,aa=V.ref,ba=V.inputRef,ca=V.handleClick,da=V.mutableRefs,ea=V.setWithValue,fa=useSortSteps({step:I,min:H,max:G}),ga=useMutableRef([fa,H,G,J,stepIsActive(fa,k)]),ha=useCallback(function(a,b){var c,d;if(ba.current&&!da.current[4]){var e=getValueByStep(ga.current[0],ba.current.value,b,ga.current[1],ga.current[2]);null===(c=(d=da.current)[0])||void 0===c?void 0:c.call(d,e,{e:a}),ba.current.value=e,ea.on()}},[]),ia=useCallback(function(a){return ha(a,!0)},[]),ja=useCallback(function(a){return ha(a,!1)},[]),ka=useKeys(useMemo(function(){return{isActive:!0,keys:{ArrowUp:function ArrowUp(a){a.preventDefault(),ga.current[4]&&ha(a,!0)},ArrowDown:function ArrowDown(a){a.preventDefault(),ga.current[4]&&ha(a,!1)}},onEvent:ga.current[3]}},[]));return React.createElement(FieldControlLayout,Object.assign({},U,{className:cnTextFieldTypeNumber({incrementButtons:F},[c]),form:p,status:q,size:m,leftSide:renderSide(v,m,D),rightSide:[y&&!k&&_&&!F&&React.createElement(FieldClearButton,{size:m,onClick:Y}),F&&ga.current[4]&&React.createElement(FieldCounter,{onIncrementClick:ia,onIncrementFocus:Z,onDecrementClick:ja,onDecrementFocus:Z})],focused:$,view:o,ref:useForkRef([b,aa]),disabled:k,onClick:ca}),React.createElement(FieldInput,{className:cnTextFieldTypeNumber("Input"),placeholder:u,autoFocus:t,autoComplete:x,onBlur:W,onChange:X,onFocus:Z,defaultValue:e||void 0,value:null===d?"":d,ref:useForkRef([i,ba]),readOnly:z,tabIndex:B,"aria-label":C,onKeyDown:ka,onKeyDownCapture:K,onKeyUp:L,onKeyUpCapture:M,maxLength:j,disabled:k,type:A,max:G,min:H,id:g,name:h,onCopy:N,onCopyCapture:O,onCut:P,onCutCapture:Q,onPaste:R,onPasteCapture:S}))});
//# sourceMappingURL=TextFieldTypeNumber.js.map