import{o as e}from"./chunk.DuxOD-Sk.js";import{r as t}from"./emotion-is-prop-valid.esm.DV_OErv-.js";import{c as n,l as r,t as i}from"./emotion-styled.browser.esm.BPUx6WuE.js";import{B as a,y as o,yt as s}from"./src.sR_9Xh2m.js";import{t as c}from"./useEmotionTheme.61kSPILX.js";import{N as l,T as u,n as d}from"./utils.B9mvrYZE.js";import{l as f}from"./utils.C5b8Q4FE.js";import{i as p}from"./useWindowDimensionsContext.gRLzw0wB.js";import{n as m}from"./useBasicWidgetState.DAZ7WsXN.js";import{n as h,t as g}from"./useTextInputAutoExpand.DOKACicv.js";import{t as _}from"./InputInstructions.Dcgro9cw.js";import{n as v,r as y,t as b}from"./useUpdateUiValue.D01djDVK.js";var x=e(t()),S=(e,t)=>{let n=`auto`;if(e.heightConfig?.useStretch)n=`100%`;else if(e.heightConfig?.pixelHeight&&e.heightConfig.pixelHeight>0){let r=l(t.labelVisibility?.value)===d.Collapsed?2:30,i=e.heightConfig.pixelHeight-r;n=`${Math.max(0,i)}px`}return n},C=i(`div`,{target:`e1tmb1p40`})({height:`100%`,display:`flex`,flexDirection:`column`}),w=(e,t)=>e.getStringValue(t)??null,T=e=>e.default??null,E=e=>e.value??null,ee=(e,t,n,r)=>{t.setStringValue(e,n.value,{fromUi:n.fromUi},r)},D=(0,x.memo)(({disabled:e,element:t,widgetMgr:i,fragmentId:d,outerElement:D})=>{let O=(0,x.useId)(),{width:k,elementRef:A}=p(),[j,M]=(0,x.useState)(!1),[N,P]=(0,x.useState)(!1),F=D.heightConfig?.useContent??!1,I=D.heightConfig?.useStretch??!1,L=S(D,t),R=(0,x.useRef)(null),[z,B]=(0,x.useState)(()=>w(i,t)??null),[V,H]=m({getStateFromWidgetMgr:w,getDefaultStateFromProto:T,getCurrStateFromProto:E,updateWidgetMgrState:ee,element:t,widgetMgr:i,fragmentId:d,formClearBehavior:`resetValueAndRunCallback`,onFormCleared:(0,x.useCallback)(()=>{B(t.default??null),M(!0)},[t]),queryParamBinding:t.queryParamKey?{paramKey:t.queryParamKey,valueType:`string_value`,clearable:!0}:void 0});b(V,z,B,j);let U=c(),W=(0,x.useRef)(!1),{height:G,maxHeight:K,updateScrollHeight:q}=g({textareaRef:R,dependencies:[t.placeholder,...F?[z]:[V]]});(0,x.useLayoutEffect)(()=>{F&&k>0&&!W.current&&(W.current=!0,q())},[F,k,q]);let J=(0,x.useCallback)(()=>{M(!1),H({value:z,fromUi:!0})},[z,H]),Y=(0,x.useCallback)(()=>{j&&J(),P(!1)},[j,J]),X=(0,x.useCallback)(()=>{P(!0)},[]),Z=(0,x.useCallback)(()=>{F&&q()},[F,q]),Q=y({formId:t.formId,maxChars:t.maxChars,setDirty:M,setUiValue:B,setValueWithSource:H,additionalAction:Z}),te=v(t.formId,J,j,i,d,!0),{placeholder:ne,formId:$}=t,re=u({formId:$})?i.allowFormEnterToSubmit($):j,ie=N&&k>f(U.breakpoints.hideWidgetDetails);return r(C,{className:`stTextArea`,"data-testid":`stTextArea`,ref:A,children:[n(a,{label:t.label,disabled:e,labelVisibility:l(t.labelVisibility?.value),htmlFor:O,children:t.help&&n(o,{content:t.help,label:t.label})}),n(h,{inputRef:F?R:void 0,value:z??``,placeholder:ne,onBlur:Y,onFocus:X,onChange:Q,onKeyDown:te,"aria-label":t.label,disabled:e,id:O,overrides:{Input:{style:{fontWeight:U.fontWeights.normal,lineHeight:U.lineHeights.inputWidget,height:F?G:L,maxHeight:F?K:``,minHeight:U.sizes.largestElementHeight,resize:I?`none`:`vertical`,paddingRight:U.spacing.md,paddingLeft:U.spacing.md,paddingBottom:U.spacing.md,paddingTop:U.spacing.md,"::placeholder":{color:U.colors.fadedText60}}},Root:{props:{"data-testid":`stTextAreaRootElement`},style:({$isFocused:e})=>{let t=s(U.colors,e);return{borderLeftWidth:U.sizes.borderWidth,borderRightWidth:U.sizes.borderWidth,borderTopWidth:U.sizes.borderWidth,borderBottomWidth:U.sizes.borderWidth,borderTopColor:t,borderRightColor:t,borderBottomColor:t,borderLeftColor:t,flexGrow:1}}}}}),ie&&n(_,{dirty:j,value:z??``,maxLength:t.maxChars,type:`multiline`,inForm:u({formId:$}),allowEnterToSubmit:re})]})});export{D as default};