import{o as e}from"./rolldown-runtime.DAXXjFlN.js";import{r as t}from"./emotion-is-prop-valid.esm.CygBv61C.js";import{a as n,i as r,t as i}from"./emotion-styled.browser.esm.C7ab1lZK.js";import{Jt as a,Vt as o,c as s,yt as c}from"./utils.KTqwHXHU.js";import{t as l}from"./useEmotionTheme.BIIZ9T_O.js";import{t as u}from"./useCalculatedDimensions.BnLCBgVi.js";import{t as d}from"./WidgetLabel.B3OAjMbS.js";import{t as f}from"./WidgetLabelHelpIcon.DPIlnvoY.js";import{n as p}from"./useBasicWidgetState.CCuiA4s6.js";import{t as m}from"./InputInstructions.BT3kDpbi.js";import{t as h}from"./useTextInputAutoExpand.De0nbUkX.js";import{n as g,r as _,t as v}from"./useUpdateUiValue.BWe0Q6sA.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=a(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=o({formId:$})?i.allowFormEnterToSubmit($):j,ie=N&&k>s(U.breakpoints.hideWidgetDetails);return n(x,{className:`stTextArea`,"data-testid":`stTextArea`,ref:A,children:[r(d,{label:t.label,disabled:e,labelVisibility:a(t.labelVisibility?.value),htmlFor:O,children:t.help&&r(f,{content:t.help,label:t.label})}),r(S,{"data-testid":`stTextAreaRootElement`,children:r(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&&r(m,{dirty:j,value:z??``,maxLength:t.maxChars,type:`multiline`,inForm:o({formId:$}),allowEnterToSubmit:re})]})});export{D as default};