import{Ci as e,Ft as t,Ja as n,Qa as r,Sr as i,Ya as a,cr as ee,ft as o,gi as s,io as c,sn as l,tn as u,vr as d,xi as f}from"./index.dkY5s53S.js";import{n as p}from"./useBasicWidgetState.C674_qFj.js";import{n as m,t as h}from"./useTextInputAutoExpand.5FuDn5wN.js";import{t as g}from"./InputInstructions.CdXeHGKW.js";import{n as _,r as v,t as y}from"./useUpdateUiValue.DxLOa8lS.js";var b=c(r(),1),x=(t,n)=>{let r=`auto`;if(t.heightConfig?.useStretch)r=`100%`;else if(t.heightConfig?.pixelHeight&&t.heightConfig.pixelHeight>0){let i=e(n.labelVisibility?.value)===s.Collapsed?2:30,a=t.heightConfig.pixelHeight-i;r=`${Math.max(0,a)}px`}return r},S=d(`div`,{target:`e1tmb1p40`})({height:`100%`,display:`flex`,flexDirection:`column`}),C=(e,t)=>e.getStringValue(t)??null,w=e=>e.default??null,T=e=>e.value??null,E=(e,t,n,r)=>{t.setStringValue(e,n.value,{fromUi:n.fromUi},r)},D=(0,b.memo)(({disabled:r,element:s,widgetMgr:c,fragmentId:d,outerElement:D})=>{let O=(0,b.useId)(),{width:k,elementRef:A}=u(),[j,M]=(0,b.useState)(!1),[N,P]=(0,b.useState)(!1),F=D.heightConfig?.useContent??!1,I=D.heightConfig?.useStretch??!1,L=x(D,s),R=(0,b.useRef)(null),[z,B]=(0,b.useState)(()=>C(c,s)??null),[V,H]=p({getStateFromWidgetMgr:C,getDefaultStateFromProto:w,getCurrStateFromProto:T,updateWidgetMgrState:E,element:s,widgetMgr:c,fragmentId:d,formClearBehavior:`resetValueAndRunCallback`,onFormCleared:(0,b.useCallback)(()=>{B(s.default??null),M(!0)},[s]),queryParamBinding:s.queryParamKey?{paramKey:s.queryParamKey,valueType:`string_value`,clearable:!0}:void 0});y(V,z,B,j);let U=ee(),W=(0,b.useRef)(!1),{height:G,maxHeight:K,updateScrollHeight:q}=h({textareaRef:R,dependencies:[s.placeholder,...F?[z]:[V]]});(0,b.useLayoutEffect)(()=>{F&&k>0&&!W.current&&(W.current=!0,q())},[F,k,q]);let J=(0,b.useCallback)(()=>{M(!1),H({value:z,fromUi:!0})},[z,H]),Y=(0,b.useCallback)(()=>{j&&J(),P(!1)},[j,J]),X=(0,b.useCallback)(()=>{P(!0)},[]),Z=(0,b.useCallback)(()=>{F&&q()},[F,q]),Q=v({formId:s.formId,maxChars:s.maxChars,setDirty:M,setUiValue:B,setValueWithSource:H,additionalAction:Z}),te=_(s.formId,J,j,c,d,!0),{placeholder:ne,formId:$}=s,re=f({formId:$})?c.allowFormEnterToSubmit($):j,ie=N&&k>i(U.breakpoints.hideWidgetDetails);return a(S,{className:`stTextArea`,"data-testid":`stTextArea`,ref:A,children:[n(t,{label:s.label,disabled:r,labelVisibility:e(s.labelVisibility?.value),htmlFor:O,children:s.help&&n(o,{content:s.help,label:s.label})}),n(m,{inputRef:F?R:void 0,value:z??``,placeholder:ne,onBlur:Y,onFocus:X,onChange:Q,onKeyDown:te,"aria-label":s.label,disabled:r,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=l(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(g,{dirty:j,value:z??``,maxLength:s.maxChars,type:`multiline`,inForm:f({formId:$}),allowEnterToSubmit:re})]})});export{D as default};