import{c0 as S,d2 as L,c as P,r as l,bm as _,ap as G,d3 as W,j as s,b$ as $,ch as J,c1 as K,bJ as N}from"./index-DCNLpqIv.js";import{u as O}from"./uniqueId-Dgo2nsPZ.js";import{I as q}from"./InputInstructions-BgxdtQsQ.js";import{a as Q}from"./useBasicWidgetState-9vtYd9vP.js";import{u as X,a as Y,b as Z}from"./useUpdateUiValue-BF7Ryinr.js";import{u as ee,T as te}from"./useTextInputAutoExpand-BFx1z0yW.js";import"./FormClearHelper-fvwQICEk.js";import"./inputUtils-CptNuJwn.js";import"./base-input-D2OIsCyG.js";const ie=(t,e)=>{let a="auto";if(t.heightConfig?.useStretch)a="100%";else if(t.heightConfig?.pixelHeight&&t.heightConfig.pixelHeight>0){const r=S(e.labelVisibility?.value)===L.Collapsed?2:30;a=`${t.heightConfig.pixelHeight-r}px`}return a},ae=P("div",{target:"ezh4s2r0"})({name:"kdbhus",styles:"height:100%;display:flex;flex-direction:column"}),v=(t,e)=>t.getStringValue(e)??e.default??null,le=t=>t.default??null,re=t=>t.value??null,oe=(t,e,a,r)=>{e.setStringValue(t,a.value,{fromUi:a.fromUi},r)},se=({disabled:t,element:e,widgetMgr:a,fragmentId:r,outerElement:h})=>{const c=l.useRef(O("text_area_")).current,[y,H]=_(),[o,m]=l.useState(!1),[I,b]=l.useState(!1),d=h.heightConfig?.useContent??!1,T=h.heightConfig?.useStretch??!1,R=ie(h,e),x=l.useRef(null),[n,g]=l.useState(()=>v(a,e)??null),F=l.useCallback(()=>{g(e.default??null),m(!0)},[e]),[j,u]=Q({getStateFromWidgetMgr:v,getDefaultStateFromProto:le,getCurrStateFromProto:re,updateWidgetMgrState:oe,element:e,widgetMgr:a,fragmentId:r,onFormCleared:F});X(j,n,g,o);const i=G(),{height:k,maxHeight:z,updateScrollHeight:C}=ee({textareaRef:x,dependencies:[e.placeholder]}),p=l.useCallback(()=>{m(!1),u({value:n,fromUi:!0})},[n,u]),V=l.useCallback(()=>{o&&p(),b(!1)},[o,p]),w=l.useCallback(()=>{b(!0)},[]),E=l.useCallback(()=>{d&&C()},[d,C]),A=Y({formId:e.formId,maxChars:e.maxChars,setDirty:m,setUiValue:g,setValueWithSource:u,additionalAction:E}),D=Z(e.formId,p,o,a,r,!0),{placeholder:M,formId:f}=e,U=W({formId:f})?a.allowFormEnterToSubmit(f):o,B=I&&y>i.breakpoints.hideWidgetDetails;return s.jsxs(ae,{className:"stTextArea","data-testid":"stTextArea",ref:H,children:[s.jsx($,{label:e.label,disabled:t,labelVisibility:S(e.labelVisibility?.value),htmlFor:c,children:e.help&&s.jsx(J,{children:s.jsx(K,{content:e.help,placement:N.TOP_RIGHT})})}),s.jsx(te,{inputRef:d?x:void 0,value:n??"",placeholder:M,onBlur:V,onFocus:w,onChange:A,onKeyDown:D,"aria-label":e.label,disabled:t,id:c,overrides:{Input:{style:{fontWeight:i.fontWeights.normal,lineHeight:i.lineHeights.inputWidget,height:d?k:R,maxHeight:d?z:"",minHeight:i.sizes.largestElementHeight,resize:T?"none":"vertical",paddingRight:i.spacing.md,paddingLeft:i.spacing.md,paddingBottom:i.spacing.md,paddingTop:i.spacing.md,"::placeholder":{color:i.colors.fadedText60}}},Root:{props:{"data-testid":"stTextAreaRootElement"},style:{borderLeftWidth:i.sizes.borderWidth,borderRightWidth:i.sizes.borderWidth,borderTopWidth:i.sizes.borderWidth,borderBottomWidth:i.sizes.borderWidth,flexGrow:1}}}}),B&&s.jsx(q,{dirty:o,value:n??"",maxLength:e.maxChars,type:"multiline",inForm:W({formId:f}),allowEnterToSubmit:U})]})},de=l.memo(se);export{de as default};
