import{p as W,aB as K,F as O,r as i,k as _,l as $,aa as S,o as G,j as c,ab as M,ac as N,ae as J}from"./index.CS3tpmQq.js";import{I as Q}from"./InputInstructions.DNVNePDU.js";import{u as X}from"./useBasicWidgetState.DxPSDiCY.js";import{u as Y,a as Z,b as tt}from"./useUpdateUiValue.BIOar76Q.js";import{u as et,T as ot}from"./useTextInputAutoExpand.BcX0HWJh.js";import{u as at}from"./uniqueId.C-ekQlC4.js";import"./FormClearHelper.DyKNX1aO.js";import"./inputUtils.CptNuJwn.js";import"./base-input.DfcQke7n.js";const it=(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)===K.Collapsed?2:30,l=e.heightConfig.pixelHeight-s;a=`${Math.max(0,l)}px`}return a},st=O("div",{target:"e1r0q00f0"})({height:"100%",display:"flex",flexDirection:"column"}),T=(e,t)=>e.getStringValue(t)??t.default??null,rt=e=>e.default??null,lt=e=>e.value??null,nt=(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.useRef(at("text_area_")).current,{width:y,elementRef:V}=_(),[r,g]=i.useState(!1),[I,x]=i.useState(!1),n=l.heightConfig?.useContent??!1,F=l.heightConfig?.useStretch??!1,v=it(l,t),C=i.useRef(null),[u,p]=i.useState(()=>T(a,t)??null),A=i.useCallback(()=>{p(t.default??null),g(!0)},[t]),[R,f]=X({getStateFromWidgetMgr:T,getDefaultStateFromProto:rt,getCurrStateFromProto:lt,updateWidgetMgrState:nt,element:t,widgetMgr:a,fragmentId:s,onFormCleared:A});Y(R,u,p,r);const o=$(),{height:k,maxHeight:B,updateScrollHeight:H}=et({textareaRef:C,dependencies:[t.placeholder]}),m=i.useCallback(()=>{g(!1),f({value:u,fromUi:!0})},[u,f]),L=i.useCallback(()=>{r&&m(),x(!1)},[r,m]),z=i.useCallback(()=>{x(!0)},[]),D=i.useCallback(()=>{n&&H()},[n,H]),E=Z({formId:t.formId,maxChars:t.maxChars,setDirty:g,setUiValue:p,setValueWithSource:f,additionalAction:D}),U=tt(t.formId,m,r,a,s,!0),{placeholder:P,formId:b}=t,j=S({formId:b})?a.allowFormEnterToSubmit(b):r,w=I&&y>o.breakpoints.hideWidgetDetails;return G(st,{className:"stTextArea","data-testid":"stTextArea",ref:V,children:[c(N,{label:t.label,disabled:e,labelVisibility:W(t.labelVisibility?.value),htmlFor:h,children:t.help&&c(M,{content:t.help,label:t.label})}),c(ot,{inputRef:n?C:void 0,value:u??"",placeholder:P,onBlur:L,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?k:v,maxHeight:n?B:"",minHeight:o.sizes.largestElementHeight,resize:F?"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:q})=>{const d=J(o.colors,q);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}}}}}),w&&c(Q,{dirty:r,value:u??"",maxLength:t.maxChars,type:"multiline",inForm:S({formId:b}),allowEnterToSubmit:j})]})},Ct=i.memo(ut);export{Ct as default};
