import{aH as S,aF as G,A as N,b as i,Y as O,N as _,dG as T,E as M,j as Y,c,db as $}from"./index.BdH_oWMm.js";import{I as J}from"./InputInstructions.DGHznNow.js";import{W as Q}from"./WidgetLabel.ZStEr2fI.js";import{W as X}from"./WidgetLabelHelpIcon.CochPswC.js";import{a as Z}from"./useBasicWidgetState.U_bd_Q53.js";import{u as tt,a as et,b as ot}from"./useUpdateUiValue.6fG_KG41.js";import{u as at,T as it}from"./useTextInputAutoExpand.egyiMYeN.js";import"./styled-components.jdcyFPSS.js";import"./FormClearHelper.B3vyDvH9.js";import"./inputUtils.CptNuJwn.js";import"./base-input.Dg8TnJbw.js";import"./constants.Bk9yhl7Y.js";const st=(e,t)=>{let a="auto";if(e.heightConfig?.useStretch)a="100%";else if(e.heightConfig?.pixelHeight&&e.heightConfig.pixelHeight>0){const s=S(t.labelVisibility?.value)===G.Collapsed?2:30,l=e.heightConfig.pixelHeight-s;a=`${Math.max(0,l)}px`}return a},rt=N("div",{target:"e1tmb1p40"})({height:"100%",display:"flex",flexDirection:"column"}),W=(e,t)=>e.getStringValue(t)??null,lt=e=>e.default??null,nt=e=>e.value??null,dt=(e,t,a,s)=>{t.setStringValue(e,a.value,{fromUi:a.fromUi},s)},ut=({disabled:e,element:t,widgetMgr:a,fragmentId:s,outerElement:l})=>{const h=i.useId(),{width:v,elementRef:V}=O(),[r,g]=i.useState(!1),[A,x]=i.useState(!1),n=l.heightConfig?.useContent??!1,I=l.heightConfig?.useStretch??!1,F=st(l,t),C=i.useRef(null),[d,p]=i.useState(()=>W(a,t)??null),R=i.useCallback(()=>{p(t.default??null),g(!0)},[t]),B=t.queryParamKey?{paramKey:t.queryParamKey,valueType:"string_value",clearable:!0}:void 0,[y,m]=Z({getStateFromWidgetMgr:W,getDefaultStateFromProto:lt,getCurrStateFromProto:nt,updateWidgetMgrState:dt,element:t,widgetMgr:a,fragmentId:s,formClearBehavior:"resetValueAndRunCallback",onFormCleared:R,queryParamBinding:B});tt(y,d,p,r);const o=_(),{height:P,maxHeight:k,updateScrollHeight:H}=at({textareaRef:C,dependencies:[t.placeholder,y]}),f=i.useCallback(()=>{g(!1),m({value:d,fromUi:!0})},[d,m]),E=i.useCallback(()=>{r&&f(),x(!1)},[r,f]),L=i.useCallback(()=>{x(!0)},[]),z=i.useCallback(()=>{n&&H()},[n,H]),D=et({formId:t.formId,maxChars:t.maxChars,setDirty:g,setUiValue:p,setValueWithSource:m,additionalAction:z}),U=ot(t.formId,f,r,a,s,!0),{placeholder:K,formId:b}=t,j=T({formId:b})?a.allowFormEnterToSubmit(b):r,q=A&&v>M(o.breakpoints.hideWidgetDetails);return Y(rt,{className:"stTextArea","data-testid":"stTextArea",ref:V,children:[c(Q,{label:t.label,disabled:e,labelVisibility:S(t.labelVisibility?.value),htmlFor:h,children:t.help&&c(X,{content:t.help,label:t.label})}),c(it,{inputRef:n?C:void 0,value:d??"",placeholder:K,onBlur:E,onFocus:L,onChange:D,onKeyDown:U,"aria-label":t.label,disabled:e,id:h,overrides:{Input:{style:{fontWeight:o.fontWeights.normal,lineHeight:o.lineHeights.inputWidget,height:n?P:F,maxHeight:n?k:"",minHeight:o.sizes.largestElementHeight,resize:I?"none":"vertical",paddingRight:o.spacing.md,paddingLeft:o.spacing.md,paddingBottom:o.spacing.md,paddingTop:o.spacing.md,"::placeholder":{color:o.colors.fadedText60}}},Root:{props:{"data-testid":"stTextAreaRootElement"},style:({$isFocused:w})=>{const u=$(o.colors,w);return{borderLeftWidth:o.sizes.borderWidth,borderRightWidth:o.sizes.borderWidth,borderTopWidth:o.sizes.borderWidth,borderBottomWidth:o.sizes.borderWidth,borderTopColor:u,borderRightColor:u,borderBottomColor:u,borderLeftColor:u,flexGrow:1}}}}}),q&&c(J,{dirty:r,value:d??"",maxLength:t.maxChars,type:"multiline",inForm:T({formId:b}),allowEnterToSubmit:j})]})},Wt=i.memo(ut);export{Wt as default};
