import{o as e}from"./rolldown-runtime.DAXXjFlN.js";import{r as t}from"./emotion-is-prop-valid.esm.CygBv61C.js";import{c as n,l as r,t as i}from"./emotion-styled.browser.esm.DmHEQgFq.js";import{c as a}from"./utils.Dw3nndTc.js";import{N as o,T as s,n as c}from"./utils.CmclnrwZ.js";import{t as l}from"./useEmotionTheme.tyjAwN1A.js";import{Qt as u,at as d,nt as f}from"./index.D3kRk1xg.js";import{n as p}from"./useBasicWidgetState.Bh_1DRpL.js";import{t as m}from"./InputInstructions.DScrKUse.js";import{t as h}from"./useTextInputAutoExpand.oDEOWqG6.js";import{n as g,r as _,t as v}from"./useUpdateUiValue.CT93eHPI.js";var y=e(t(),1),b=(e,t)=>{let n=`auto`;if(e.heightConfig?.useStretch)n=`100%`;else if(e.heightConfig?.pixelHeight&&e.heightConfig.pixelHeight>0){let r=o(t.labelVisibility?.value)===c.Collapsed?2:30,i=e.heightConfig.pixelHeight-r;n=`${Math.max(0,i)}px`}return n},x=i(`div`,{target:`e1wz7dbj0`})({height:`100%`,display:`flex`,flexDirection:`column`}),S=i(`div`,{target:`e1wz7dbj1`})(({theme:e})=>({border:`${e.sizes.borderWidth} solid`,borderColor:e.colors.widgetBorderColor??e.colors.secondaryBg,borderRadius:e.radii.default,backgroundColor:e.colors.secondaryBg,flexGrow:1,"&:focus-within":{borderColor:e.colors.primary}})),C=i(`textarea`,{target:`e1wz7dbj2`})(({theme:e,$height:t,$maxHeight:n,$resize:r})=>({width:`100%`,height:t,maxHeight:n,minHeight:e.sizes.largestElementHeight,resize:r,fontWeight:e.fontWeights.normal,lineHeight:e.lineHeights.inputWidget,fontFamily:`inherit`,fontSize:e.fontSizes.sm,color:`inherit`,backgroundColor:`transparent`,border:`none`,outline:`none`,boxSizing:`border-box`,display:`block`,overflowY:`auto`,padding:e.spacing.md,"&::placeholder":{color:e.colors.fadedText60},"&:disabled":{cursor:`not-allowed`,color:e.colors.fadedText40,WebkitTextFillColor:e.colors.fadedText40}})),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,y.memo)(({disabled:e,element:t,widgetMgr:i,fragmentId:c,outerElement:D})=>{let O=(0,y.useId)(),{width:k,elementRef:A}=u(),[j,M]=(0,y.useState)(!1),[N,P]=(0,y.useState)(!1),F=D.heightConfig?.useContent??!1,I=D.heightConfig?.useStretch??!1,L=b(D,t),R=(0,y.useRef)(null),[z,B]=(0,y.useState)(()=>w(i,t)??null),[V,H]=p({getStateFromWidgetMgr:w,getDefaultStateFromProto:T,getCurrStateFromProto:E,updateWidgetMgrState:ee,element:t,widgetMgr:i,fragmentId:c,formClearBehavior:`resetValueAndRunCallback`,onFormCleared:(0,y.useCallback)(()=>{B(t.default??null),M(!0)},[t]),queryParamBinding:t.queryParamKey?{paramKey:t.queryParamKey,valueType:`string_value`,clearable:!0}:void 0});v(V,z,B,j);let U=l(),W=(0,y.useRef)(!1),{height:G,maxHeight:K,updateScrollHeight:q}=h({textareaRef:R,dependencies:[t.placeholder,...F?[z]:[V]]});(0,y.useLayoutEffect)(()=>{F&&k>0&&!W.current&&(W.current=!0,q())},[F,k,q]);let J=(0,y.useCallback)(()=>{M(!1),H({value:z,fromUi:!0})},[z,H]),Y=(0,y.useCallback)(()=>{j&&J(),P(!1)},[j,J]),X=(0,y.useCallback)(()=>{P(!0)},[]),Z=(0,y.useCallback)(()=>{F&&q()},[F,q]),Q=_({formId:t.formId,maxChars:t.maxChars,setDirty:M,setUiValue:B,setValueWithSource:H,additionalAction:Z}),te=g(t.formId,J,j,i,c,!0),{placeholder:ne,formId:$}=t,re=s({formId:$})?i.allowFormEnterToSubmit($):j,ie=N&&k>a(U.breakpoints.hideWidgetDetails);return r(x,{className:`stTextArea`,"data-testid":`stTextArea`,ref:A,children:[n(d,{label:t.label,disabled:e,labelVisibility:o(t.labelVisibility?.value),htmlFor:O,children:t.help&&n(f,{content:t.help,label:t.label})}),n(S,{"data-testid":`stTextAreaRootElement`,children:n(C,{ref:F?R:void 0,value:z??``,placeholder:ne,onBlur:Y,onFocus:X,onChange:Q,onKeyDown:te,"aria-label":t.label,disabled:e,id:O,rows:3,$height:F?G:L,$maxHeight:F?K:``,$resize:I?`none`:`vertical`})}),ie&&n(m,{dirty:j,value:z??``,maxLength:t.maxChars,type:`multiline`,inForm:s({formId:$}),allowEnterToSubmit:re})]})});export{D as default};