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