import{o as e}from"./rolldown-runtime.C0FnF6B9.js";import{r as t}from"./emotion-is-prop-valid.esm.CuYlOKOk.js";import{a as n,i as r,t as i}from"./emotion-styled.browser.esm.BYv_Qzcq.js";import{$ as a,c as o,j as s,ot as c}from"./utils.Vs712G4Z.js";import{t as l}from"./useEmotionTheme.Dmt_qJ4x.js";import{t as u}from"./useCalculatedDimensions.DmyA6xJn.js";import{t as d}from"./WidgetLabel.Cr4ld6Ih.js";import{t as f}from"./WidgetLabelHelpIcon.DusqDQ1k.js";import{n as p}from"./useBasicWidgetState.ssY2f7Zy.js";import{t as m}from"./InputInstructions.BdRjLMGx.js";import{t as h}from"./useTextInputAutoExpand.DzgRRH2p.js";import{t as g}from"./inputUtils.CD44xxT-.js";import{n as _,t as v}from"./useUpdateUiValue.p9BcgoMl.js";var y=e(t(),1);function b(e,t,n,r,i,a=!1){return(0,y.useCallback)(o=>{let s=!a||o.metaKey||o.ctrlKey;!g(o)||!s||(o.preventDefault(),n&&t(),r.allowFormEnterToSubmit(e)&&r.submitForm(e,i))},[e,i,n,t,r,a])}var ee=(e,t)=>{let n=`auto`;if(e.heightConfig?.useStretch)n=`100%`;else if(e.heightConfig?.pixelHeight&&e.heightConfig.pixelHeight>0){let r=c(t.labelVisibility?.value)===s.Collapsed?2:30,i=e.heightConfig.pixelHeight-r;n=`${Math.max(0,i)}px`}return n},x=i(`div`,{target:`e1wz7dbj0`})({height:`100%`,display:`flex`,flexDirection:`column`}),S=i(`div`,{target:`e1wz7dbj1`})(({theme:e})=>({border:`${e.sizes.borderWidth} solid`,borderColor:e.colors.widgetBorderColor??e.colors.secondaryBg,borderRadius:e.radii.default,backgroundColor:e.colors.secondaryBg,flexGrow:1,"&:focus-within":{borderColor:e.colors.primary}})),C=i(`textarea`,{target:`e1wz7dbj2`})(({theme:e,$height:t,$maxHeight:n,$resize:r})=>({width:`100%`,height:t,maxHeight:n,minHeight:e.sizes.largestElementHeight,resize:r,fontWeight:e.fontWeights.normal,lineHeight:e.lineHeights.inputWidget,fontFamily:`inherit`,fontSize:e.fontSizes.sm,color:`inherit`,backgroundColor:`transparent`,border:`none`,outline:`none`,boxSizing:`border-box`,display:`block`,overflowY:`auto`,padding:e.spacing.md,"&::placeholder":{color:e.colors.fadedText60},"&:disabled":{cursor:`not-allowed`,color:e.colors.fadedText40,WebkitTextFillColor:e.colors.fadedText40}})),w=(e,t)=>e.getStringValue(t)??null,T=e=>e.default??null,te=e=>e.value??null,E=(e,t,n,r)=>{t.setStringValue(e,n.value,{fromUi:n.fromUi},r)},D=(0,y.memo)(({disabled:e,element:t,widgetMgr:i,fragmentId:s,outerElement:g})=>{let D=(0,y.useId)(),{width:O,elementRef:k}=u(),[A,j]=(0,y.useState)(!1),[M,N]=(0,y.useState)(!1),P=g.heightConfig?.useContent??!1,F=g.heightConfig?.useStretch??!1,I=ee(g,t),L=(0,y.useRef)(null),[R,z]=(0,y.useState)(()=>w(i,t)??null),B=(0,y.useCallback)(()=>{z(t.default??null),j(!0)},[t]),V=t.queryParamKey?{paramKey:t.queryParamKey,valueType:`string_value`,clearable:!0}:void 0,[H,U]=p({getStateFromWidgetMgr:w,getDefaultStateFromProto:T,getCurrStateFromProto:te,updateWidgetMgrState:E,element:t,widgetMgr:i,fragmentId:s,formClearBehavior:`resetValueAndRunCallback`,onFormCleared:B,queryParamBinding:V});v(H,R,z,A);let W=l(),G=(0,y.useRef)(!1),{height:K,maxHeight:q,updateScrollHeight:J}=h({textareaRef:L,dependencies:[t.placeholder,...P?[R]:[H]]});(0,y.useLayoutEffect)(()=>{P&&O>0&&!G.current&&(G.current=!0,J())},[P,O,J]);let Y=(0,y.useCallback)(()=>{j(!1),U({value:R,fromUi:!0})},[R,U]),X=(0,y.useCallback)(()=>{A&&Y(),N(!1)},[A,Y]),Z=(0,y.useCallback)(()=>{N(!0)},[]),Q=(0,y.useCallback)(()=>{P&&J()},[P,J]),ne=_({formId:t.formId,maxChars:t.maxChars,setDirty:j,setUiValue:z,setValueWithSource:U,additionalAction:Q}),re=b(t.formId,Y,A,i,s,!0),{placeholder:ie,formId:$}=t,ae=a({formId:$})?i.allowFormEnterToSubmit($):A,oe=M&&O>o(W.breakpoints.hideWidgetDetails);return n(x,{className:`stTextArea`,"data-testid":`stTextArea`,ref:k,children:[r(d,{label:t.label,disabled:e,labelVisibility:c(t.labelVisibility?.value),htmlFor:D,children:t.help&&r(f,{content:t.help,label:t.label})}),r(S,{"data-testid":`stTextAreaRootElement`,children:r(C,{ref:P?L:void 0,value:R??``,placeholder:ie,onBlur:X,onFocus:Z,onChange:ne,onKeyDown:re,"aria-label":t.label,disabled:e,id:D,rows:3,$height:P?K:I,$maxHeight:P?q:``,$resize:F?`none`:`vertical`})}),oe&&r(m,{dirty:A,value:R??``,maxLength:t.maxChars,type:`multiline`,inForm:a({formId:$}),allowEnterToSubmit:ae})]})});export{D as default};