import{__rest as e}from"../../../_virtual/_tslib.js";import a,{forwardRef as n,useRef as t,useMemo as o}from"react";import r from"classnames";import i from"./hooks/useNumberFieldState.js";import l from"./hooks/useSpinButtonHandlers.js";import s from"../FieldLabel/FieldLabel.js";import d from"../InfoText/InfoText.js";import m from"./components/NumberFieldSpinButton/NumberFieldSpinButton.js";import u from"./NumberField.module.scss.js";import c from"../../hooks/useMergeRef.js";import{ComponentVibeId as p}from"../../tests/constants.js";import f from"../../../components/icon/dist/Icon/Icon.js";import b from"../../../components/layout/dist/Flex/Flex.js";import x from"../../../base/dist/BaseInput/BaseInput.js";var h=n((function(n,h){var v=n.className,y=n.value,O=n.onChange,g=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=c(h,K),U=i({value:y,onChange:O,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:O,value:J,step:R,min:w,max:M,allowOutOfBounds:S,readOnly:E,inputRef:K}),Z=Y.onIncrement,$=Y.onDecrement,ee=o((function(){return q?a.createElement(f,{icon:q,className:u.leftIcon}):null}),[q]),ae=o((function(){return a.createElement(m,{inputId:A,onIncrement:Z,onDecrement:$,disabled:C||E,size:V,isAtMin:W,isAtMax:X})}),[A,Z,$,C,E,V,W,X]),ne=o((function(){return F&&A?"".concat(A,"-info-text"):void 0}),[F,A]),te=o((function(){return g&&A?"".concat(A,"-label"):void 0}),[g,A]);return a.createElement(b,{direction:"column",align:"stretch",gap:"xs",className:r(u.numberField,v),"data-vibe":p.NUMBER_FIELD},a.createElement(s,{id:te,className:u.label,labelText:g,required:j,labelFor:A}),a.createElement(x,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||g,"aria-labelledby":te,"aria-describedby":ne,disabled:C,readOnly:E,size:V,error:B,success:N,renderLeft:ee,renderRight:ae})),a.createElement(d,{id:ne,text:F,error:B,success:N,disabled:C,readOnly:E}))}));export{h as default};
//# sourceMappingURL=NumberField.js.map
