import{o as e}from"./chunk.DuxOD-Sk.js";import{r as t}from"./emotion-is-prop-valid.esm.DV_OErv-.js";import{c as n,l as r,t as i}from"./emotion-styled.browser.esm.BPUx6WuE.js";import{L as a}from"./protobuf.DyZGXwGk.js";import{B as o,y as s,yt as c}from"./src.sR_9Xh2m.js";import{t as l}from"./useEmotionTheme.61kSPILX.js";import{N as u,T as d}from"./utils.B9mvrYZE.js";import{l as f}from"./utils.C5b8Q4FE.js";import{r as p,t as m}from"./DynamicIcon.BDXbm0Of.js";import{i as h}from"./useWindowDimensionsContext.gRLzw0wB.js";import{t as g}from"./input.JAXO5TKy.js";import{n as _}from"./useBasicWidgetState.DAZ7WsXN.js";import{t as v}from"./InputInstructions.Dcgro9cw.js";import{n as y,r as b,t as x}from"./useUpdateUiValue.D01djDVK.js";var S=e(t()),C=i(`div`,{target:`eiqkja70`})(`position:relative;`);function w({disabled:e,element:t,widgetMgr:i,fragmentId:a}){let[w,A]=(0,S.useState)(()=>T(i,t)??null),{width:j,elementRef:M}=h(),[N,P]=(0,S.useState)(!1),[F,I]=_({getStateFromWidgetMgr:T,getDefaultStateFromProto:E,getCurrStateFromProto:D,updateWidgetMgrState:O,element:t,widgetMgr:i,fragmentId:a,formClearBehavior:`resetValueAndRunCallback`,onFormCleared:(0,S.useCallback)(()=>{A(t.default??null),P(!0)},[t.default]),queryParamBinding:t.queryParamKey?{paramKey:t.queryParamKey,valueType:`string_value`,clearable:!0}:void 0});x(F,w,A,N);let[L,R]=(0,S.useState)(!1),z=l(),B=(0,S.useId)(),{placeholder:V,formId:H,icon:U,maxChars:W}=t,G=(0,S.useCallback)(()=>{P(!1),I({value:w,fromUi:!0})},[w,I]),K=d({formId:H})?i.allowFormEnterToSubmit(H):N,q=L&&j>f(z.breakpoints.hideWidgetDetails),J=(0,S.useCallback)(()=>{N&&G(),R(!1)},[N,G]),Y=(0,S.useCallback)(()=>{R(!0)},[]),X=b({formId:H,maxChars:W,setDirty:P,setUiValue:A,setValueWithSource:I}),Z=y(H,G,N,i,a);return r(C,{className:`stTextInput`,"data-testid":`stTextInput`,ref:M,children:[n(o,{label:t.label,disabled:e,labelVisibility:u(t.labelVisibility?.value),htmlFor:B,children:t.help&&n(s,{content:t.help,label:t.label})}),n(g,{value:w??``,placeholder:V,onBlur:J,onFocus:Y,onChange:X,onKeyPress:Z,"aria-label":t.label,disabled:e,id:B,type:k(t),autoComplete:t.autocomplete,startEnhancer:U&&n(m,{"data-testid":`stTextInputIcon`,iconValue:U,size:`lg`}),overrides:{Input:{style:{fontWeight:z.fontWeights.normal,minWidth:0,lineHeight:z.lineHeights.inputWidget,paddingRight:z.spacing.sm,paddingLeft:z.spacing.md,paddingBottom:z.spacing.sm,paddingTop:z.spacing.sm,"::placeholder":{color:z.colors.fadedText60}}},Root:{props:{"data-testid":`stTextInputRootElement`},style:({$isFocused:e})=>{let t=c(z.colors,e);return{height:z.sizes.minElementHeight,borderLeftWidth:z.sizes.borderWidth,borderRightWidth:z.sizes.borderWidth,borderTopWidth:z.sizes.borderWidth,borderBottomWidth:z.sizes.borderWidth,borderTopColor:t,borderRightColor:t,borderBottomColor:t,borderLeftColor:t,paddingLeft:U?z.spacing.sm:0}}},StartEnhancer:{style:{paddingLeft:0,paddingRight:0,minWidth:z.iconSizes.lg,color:p(U)?z.colors.fadedText60:`inherit`}}}}),q&&n(v,{dirty:N,value:w??``,maxLength:W,inForm:d({formId:H}),allowEnterToSubmit:K})]})}function T(e,t){return e.getStringValue(t)??null}function E(e){return e.default??null}function D(e){return e.value??null}function O(e,t,n,r){t.setStringValue(e,n.value,{fromUi:n.fromUi},r)}function k(e){return e.type===a.Type.PASSWORD?`password`:`text`}var A=(0,S.memo)(w);export{A as default};