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