import{slicedToArray as e,defineProperty as t}from"../../../_virtual/_rollupPluginBabelHelpers.js";import{__rest as a}from"../../../_virtual/_tslib.js";import r,{forwardRef as s,useMemo as l,useState as i,useCallback as o}from"react";import n from"classnames";import{getTestId as m}from"../../tests/testIds.js";import{ComponentDefaultTestId as d,ComponentVibeId as c}from"../../tests/constants.js";import u from"./TextArea.module.scss.js";import x from"../Text/Text.js";import{Flex as p}from"@vibe/layout/mockedClassNames";import f from"../HiddenText/HiddenText.js";var h={small:3,large:4},b=s((function(s,b){var g=s.size,v=void 0===g?"small":g,T=s.rows,E=s.label,y=s.helpText,j=s.success,w=s.error,C=s.className,N=s["data-testid"],A=s.id,_=s.disabled,z=s.readOnly,L=s.required,O=s.maxLength,q=s.allowExceedingMaxLength,H=s.onChange,F=s.value,M=s.resize,P=void 0===M||M,R=s.showCharCount,X=void 0!==R&&R,k=a(s,["size","rows","label","helpText","success","error","className","data-testid","id","disabled","readOnly","required","maxLength","allowExceedingMaxLength","onChange","value","resize","showCharCount"]),B=T||h[v],I=y&&"".concat(A,"-help-text"),W=q&&"".concat(A,"-allow-exceeding-max-length"),D=l((function(){return[I,W].filter((function(e){return!!e})).join(" ")||void 0}),[I,W]),G=i((null==F?void 0:F.length)||0),J=e(G,2),K=J[0],Q=J[1],S=w||"number"==typeof O&&K>O,U=o((function(e){Q(e.target.value.length),null==H||H(e)}),[H]);return r.createElement("div",{className:n(u.textAreaWrapper,t(t(t(t({},u.error,S),u.success,j),u.disabled,_),u.readOnly,z),C),"data-testid":N||m(d.TEXT_AREA,A),"data-vibe":c.TEXT_AREA},E&&r.createElement("label",{className:n(u.label,t({},u.required,L)),htmlFor:A},E),r.createElement("textarea",Object.assign({},k,{id:A,maxLength:"number"!=typeof O||q?void 0:O,ref:b,value:F,disabled:_,readOnly:z,required:L,rows:B,className:n(u.textArea,[u[v]],t({},u.resize,P)),"aria-invalid":S,"aria-describedby":D,onChange:U})),(X||y)&&r.createElement(p,{gap:"xs",justify:"space-between",className:n(u.subTextContainer)},y&&r.createElement(x,{className:n(u.helpText),color:"inherit",id:I},y),X&&r.createElement(r.Fragment,null,r.createElement(x,{className:u.limitText},K,"number"==typeof O&&"/".concat(O)),r.createElement(f,{id:W,text:"".concat(K," out of ").concat(O)}))))}));export{b as default};
//# sourceMappingURL=TextArea.js.map
