import{t as e}from"./input.Dbu0xBeW.js";import{Ci as t,Ft as n,Ja as r,Pa as i,Qa as a,Sr as o,Ya as s,cr as c,fr as l,ft as u,io as d,mr as f,sn as p,tn as m,vr as h,xi as g}from"./index.dkY5s53S.js";import{n as _}from"./useBasicWidgetState.C674_qFj.js";import{t as v}from"./InputInstructions.CdXeHGKW.js";import{n as y,r as b,t as x}from"./useUpdateUiValue.DxLOa8lS.js";var S=d(a(),1),C=h(`div`,{target:`eiqkja70`})(`position:relative;`);function w({disabled:i,element:a,widgetMgr:d,fragmentId:h}){let[w,A]=(0,S.useState)(()=>T(d,a)??null),{width:j,elementRef:M}=m(),[N,P]=(0,S.useState)(!1),[F,I]=_({getStateFromWidgetMgr:T,getDefaultStateFromProto:E,getCurrStateFromProto:D,updateWidgetMgrState:O,element:a,widgetMgr:d,fragmentId:h,formClearBehavior:`resetValueAndRunCallback`,onFormCleared:(0,S.useCallback)(()=>{A(a.default??null),P(!0)},[a.default]),queryParamBinding:a.queryParamKey?{paramKey:a.queryParamKey,valueType:`string_value`,clearable:!0}:void 0});x(F,w,A,N);let[L,R]=(0,S.useState)(!1),z=c(),B=(0,S.useId)(),{placeholder:V,formId:H,icon:U,maxChars:W}=a,G=(0,S.useCallback)(()=>{P(!1),I({value:w,fromUi:!0})},[w,I]),K=g({formId:H})?d.allowFormEnterToSubmit(H):N,q=L&&j>o(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,d,h);return s(C,{className:`stTextInput`,"data-testid":`stTextInput`,ref:M,children:[r(n,{label:a.label,disabled:i,labelVisibility:t(a.labelVisibility?.value),htmlFor:B,children:a.help&&r(u,{content:a.help,label:a.label})}),r(e,{value:w??``,placeholder:V,onBlur:J,onFocus:Y,onChange:X,onKeyPress:Z,"aria-label":a.label,disabled:i,id:B,type:k(a),autoComplete:a.autocomplete,startEnhancer:U&&r(l,{"data-testid":`stTextInputIcon`,iconValue:U,size:`base`}),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=p(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.base,color:f(U)?z.colors.fadedText60:`inherit`}}}}),q&&r(v,{dirty:N,value:w??``,maxLength:W,inForm:g({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===i.Type.PASSWORD?`password`:`text`}var A=(0,S.memo)(w);export{A as default};