import{__rest as e}from"../../../_virtual/_tslib.js";import a,{forwardRef as n,useRef as t,useMemo as r}from"react";import o from"classnames";import i from"./hooks/useNumberFieldState.js";import l from"./hooks/useSpinButtonHandlers.js";import s from"../BaseInput/BaseInput.js";import d from"../FieldLabel/FieldLabel.js";import m from"../InfoText/InfoText.js";import u from"./components/NumberFieldSpinButton/NumberFieldSpinButton.js";import c from"./NumberField.module.scss.js";import p from"../Flex/Flex.js";import f from"../../hooks/useMergeRef.js";import{ComponentVibeId as b}from"../../tests/constants.js";import x from"../../../components/icon/dist/Icon/Icon.js";var h=n((function(n,h){var v=n.className,O=n.value,g=n.onChange,y=n.label,j=n.required,I=n.placeholder,F=n.infoText,B=n.error,N=n.success,C=n.disabled,E=n.readOnly,w=n.min,M=n.max,D=n.step,R=void 0===D?1:D,T=n.size,V=void 0===T?"medium":T,q=n.leftIcon,z=n["aria-label"],A=n.id,L=n["data-testid"],S=n.allowOutOfBounds,k=n.onValidityChange,_=e(n,["className","value","onChange","label","required","placeholder","infoText","error","success","disabled","readOnly","min","max","step","size","leftIcon","aria-label","id","data-testid","allowOutOfBounds","onValidityChange"]),K=t(null),H=f(h,K),U=i({value:O,onChange:g,min:w,max:M,step:R,disabled:C,readOnly:E,allowOutOfBounds:S,onValidityChange:k}),G=U.inputValue,J=U.numericValue,P=U.onChange,Q=U.onKeyDown,W=U.isAtMin,X=U.isAtMax,Y=l({onChange:g,value:J,step:R,min:w,max:M,allowOutOfBounds:S,readOnly:E,inputRef:K}),Z=Y.onIncrement,$=Y.onDecrement,ee=r((function(){return q?a.createElement(x,{icon:q,className:c.leftIcon}):null}),[q]),ae=r((function(){return a.createElement(u,{inputId:A,onIncrement:Z,onDecrement:$,disabled:C||E,size:V,isAtMin:W,isAtMax:X})}),[A,Z,$,C,E,V,W,X]),ne=r((function(){return F&&A?"".concat(A,"-info-text"):void 0}),[F,A]),te=r((function(){return y&&A?"".concat(A,"-label"):void 0}),[y,A]);return a.createElement(p,{direction:"column",align:"stretch",gap:"xs",className:o(c.numberField,v),"data-vibe":b.NUMBER_FIELD},a.createElement(d,{id:te,className:c.label,labelText:y,required:j,labelFor:A}),a.createElement(s,Object.assign({},_,{"data-testid":L,ref:H,id:A,value:G,onChange:P,onKeyDown:Q,placeholder:I,type:"text",inputMode:"numeric",inputRole:"spinbutton","aria-valuenow":J,"aria-valuemin":w,"aria-valuemax":M,"aria-required":j,"aria-label":z||y,"aria-labelledby":te,"aria-describedby":ne,disabled:C,readOnly:E,size:V,error:B,success:N,renderLeft:ee,renderRight:ae})),a.createElement(m,{id:ne,text:F,error:B,success:N,disabled:C,readOnly:E}))}));export{h as default};
//# sourceMappingURL=NumberField.js.map
