import{z as D,r as a,f as U,g as k,ac as S,l as H,j as r,m as j,ad as O,T as _,P as K,ae as $,af as q,ag as w,a0 as A,ah as G}from"./index.BN4Hj9cC.js";import{I as N}from"./InputInstructions.CixQ8eSs.js";import{u as J}from"./useBasicWidgetState.BL6Uby3R.js";import{u as M,a as Q,b as X}from"./useUpdateUiValue.C_MG79Ea.js";import{u as Y}from"./uniqueId.ie30vUvb.js";import{I as Z}from"./input.CEZL8u8i.js";import"./FormClearHelper.D2cMsU2H.js";import"./inputUtils.CptNuJwn.js";import"./base-input.CY9OvGfW.js";const tt=D("div",{target:"e1o1zy6o0"})("position:relative;");function et({disabled:o,element:e,widgetMgr:s,fragmentId:u}){const[n,p]=a.useState(()=>T(s,e)??null),{width:W,elementRef:y}=U(),[i,m]=a.useState(!1),x=a.useCallback(()=>{p(e.default??null),m(!0)},[e.default]),[C,h]=J({getStateFromWidgetMgr:T,getDefaultStateFromProto:ot,getCurrStateFromProto:at,updateWidgetMgrState:st,element:e,widgetMgr:s,fragmentId:u,onFormCleared:x});M(C,n,p,i);const[V,f]=a.useState(!1),t=k(),[b]=a.useState(()=>Y("text_input_")),{placeholder:F,formId:l,icon:d,maxChars:I}=e,g=a.useCallback(()=>{m(!1),h({value:n,fromUi:!0})},[n,h]),E=S({formId:l})?s.allowFormEnterToSubmit(l):i,v=V&&W>t.breakpoints.hideWidgetDetails,z=a.useCallback(()=>{i&&g(),f(!1)},[i,g]),R=a.useCallback(()=>{f(!0)},[]),L=Q({formId:l,maxChars:I,setDirty:m,setUiValue:p,setValueWithSource:h}),P=X(l,g,i,s,u);return H(tt,{className:"stTextInput","data-testid":"stTextInput",ref:y,children:[r($,{label:e.label,disabled:o,labelVisibility:j(e.labelVisibility?.value),htmlFor:b,children:e.help&&r(O,{children:r(_,{content:e.help,placement:K.TOP_RIGHT})})}),r(Z,{value:n??"",placeholder:F,onBlur:z,onFocus:R,onChange:L,onKeyPress:P,"aria-label":e.label,disabled:o,id:b,type:it(e),autoComplete:e.autocomplete,startEnhancer:d&&r(A,{"data-testid":"stTextInputIcon",iconValue:d,size:"lg"}),overrides:{Input:{style:{fontWeight:t.fontWeights.normal,minWidth:0,lineHeight:t.lineHeights.inputWidget,paddingRight:t.spacing.sm,paddingLeft:t.spacing.md,paddingBottom:t.spacing.sm,paddingTop:t.spacing.sm,"::placeholder":{color:t.colors.fadedText60}}},Root:{props:{"data-testid":"stTextInputRootElement"},style:({$isFocused:B})=>{const c=w(t.colors,B);return{height:t.sizes.minElementHeight,borderLeftWidth:t.sizes.borderWidth,borderRightWidth:t.sizes.borderWidth,borderTopWidth:t.sizes.borderWidth,borderBottomWidth:t.sizes.borderWidth,borderTopColor:c,borderRightColor:c,borderBottomColor:c,borderLeftColor:c,paddingLeft:d?t.spacing.sm:0}}},StartEnhancer:{style:{paddingLeft:0,paddingRight:0,minWidth:t.iconSizes.lg,color:q(d)?t.colors.fadedText60:"inherit"}}}}),v&&r(N,{dirty:i,value:n??"",maxLength:I,inForm:S({formId:l}),allowEnterToSubmit:E})]})}function T(o,e){return o.getStringValue(e)??null}function ot(o){return o.default??null}function at(o){return o.value??null}function st(o,e,s,u){e.setStringValue(o,s.value,{fromUi:s.fromUi},u)}function it(o){return o.type===G.Type.PASSWORD?"password":"text"}const gt=a.memo(et);export{gt as default};
