import{q as W,L as w,f as O,r as i,m as G,o as M,ak as H,O as N,h as $,j as c,aj as J}from"./index.RuhrnD1v.js";import{I as Q}from"./InputInstructions.BuiQHvdK.js";import{W as X}from"./WidgetLabel.CgwydhVR.js";import{W as Y}from"./WidgetLabelHelpIcon.BKLcvqEy.js";import{u as Z}from"./useBasicWidgetState.CI9LlGGe.js";import{u as tt,a as et,b as ot}from"./useUpdateUiValue.CyB9OGUj.js";import{u as at,T as it}from"./useTextInputAutoExpand.BeIjAsIS.js";import{u as rt}from"./uniqueId.HT2UodMD.js";import"./styled-components.CXqQ-NdV.js";import"./FormClearHelper.DFo50Lfo.js";import"./inputUtils.CptNuJwn.js";import"./base-input.DmvIDeb9.js";import"./constants.BZvTtNRL.js";const st=(e,t)=>{let a="auto";if(e.heightConfig?.useStretch)a="100%";else if(e.heightConfig?.pixelHeight&&e.heightConfig.pixelHeight>0){const r=W(t.labelVisibility?.value)===w.Collapsed?2:30,l=e.heightConfig.pixelHeight-r;a=`${Math.max(0,l)}px`}return a},lt=O("div",{target:"e1tmb1p40"})({height:"100%",display:"flex",flexDirection:"column"}),T=(e,t)=>e.getStringValue(t)??null,nt=e=>e.default??null,ut=e=>e.value??null,dt=(e,t,a,r)=>{t.setStringValue(e,a.value,{fromUi:a.fromUi},r)},ct=({disabled:e,element:t,widgetMgr:a,fragmentId:r,outerElement:l})=>{const h=i.useRef(rt("text_area_")).current,{width:S,elementRef:v}=G(),[s,g]=i.useState(!1),[V,x]=i.useState(!1),n=l.heightConfig?.useContent??!1,I=l.heightConfig?.useStretch??!1,A=st(l,t),C=i.useRef(null),[u,p]=i.useState(()=>T(a,t)??null),R=i.useCallback(()=>{p(t.default??null),g(!0)},[t]),F=t.queryParamKey?{paramKey:t.queryParamKey,valueType:"string_value",clearable:!0}:void 0,[k,m]=Z({getStateFromWidgetMgr:T,getDefaultStateFromProto:nt,getCurrStateFromProto:ut,updateWidgetMgrState:dt,element:t,widgetMgr:a,fragmentId:r,formClearBehavior:"resetValueAndRunCallback",onFormCleared:R,queryParamBinding:F});tt(k,u,p,s);const o=M(),{height:B,maxHeight:L,updateScrollHeight:y}=at({textareaRef:C,dependencies:[t.placeholder]}),f=i.useCallback(()=>{g(!1),m({value:u,fromUi:!0})},[u,m]),P=i.useCallback(()=>{s&&f(),x(!1)},[s,f]),z=i.useCallback(()=>{x(!0)},[]),D=i.useCallback(()=>{n&&y()},[n,y]),E=et({formId:t.formId,maxChars:t.maxChars,setDirty:g,setUiValue:p,setValueWithSource:m,additionalAction:D}),U=ot(t.formId,f,s,a,r,!0),{placeholder:q,formId:b}=t,K=H({formId:b})?a.allowFormEnterToSubmit(b):s,j=V&&S>N(o.breakpoints.hideWidgetDetails);return $(lt,{className:"stTextArea","data-testid":"stTextArea",ref:v,children:[c(X,{label:t.label,disabled:e,labelVisibility:W(t.labelVisibility?.value),htmlFor:h,children:t.help&&c(Y,{content:t.help,label:t.label})}),c(it,{inputRef:n?C:void 0,value:u??"",placeholder:q,onBlur:P,onFocus:z,onChange:E,onKeyDown:U,"aria-label":t.label,disabled:e,id:h,overrides:{Input:{style:{fontWeight:o.fontWeights.normal,lineHeight:o.lineHeights.inputWidget,height:n?B:A,maxHeight:n?L:"",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:_})=>{const d=J(o.colors,_);return{borderLeftWidth:o.sizes.borderWidth,borderRightWidth:o.sizes.borderWidth,borderTopWidth:o.sizes.borderWidth,borderBottomWidth:o.sizes.borderWidth,borderTopColor:d,borderRightColor:d,borderBottomColor:d,borderLeftColor:d,flexGrow:1}}}}}),j&&c(Q,{dirty:s,value:u??"",maxLength:t.maxChars,type:"multiline",inForm:H({formId:b}),allowEnterToSubmit:K})]})},vt=i.memo(ct);export{vt as default};
