import{r as i,f as P,m as D,bV as W,j as o,c as k,aI as H,aJ as U,b0 as $,aK as B,ap as M,F as _,bY as G}from"./index-D3uELfdo.js";import{I as K}from"./uniqueId-DFKpdKNq-BgvPpMK3.js";import{e as O}from"./InputInstructions-yTnPUqJo-CoOBrVL7.js";import{S as Y}from"./useBasicWidgetState-DqA4I-I_-DtgK63iS.js";import{v as A,a as J,c as N}from"./useUpdateUiValue-09I2_X1f-DW6jbCsf.js";import{a as Z}from"./input-BDVeiWWL-DMiIFeVV.js";import"./FormClearHelper-Dgu5Halt-BxICjxpW.js";import"./inputUtils-DCYiajnz-DsrlAoKH.js";import"./base-input-DjjpNP8Y-DtsTHlXD.js";const q=k("div",{target:"e11y4ecf0"})({name:"bjn8wh",styles:"position:relative"});function Q({disabled:a,element:e,widgetMgr:r,fragmentId:d}){const[l,u]=i.useState(()=>S(r,e)??null),{width:I,elementRef:T}=P(),[s,p]=i.useState(!1),y=i.useCallback(()=>{u(e.default??null),p(!0)},[e.default]),[j,c]=Y({getStateFromWidgetMgr:S,getDefaultStateFromProto:X,getCurrStateFromProto:ee,updateWidgetMgrState:te,element:e,widgetMgr:r,fragmentId:d,onFormCleared:y});A(j,l,u,s);const[C,f]=i.useState(!1),t=D(),[h]=i.useState(()=>K("text_input_")),{placeholder:F,formId:n,icon:m,maxChars:b}=e,g=i.useCallback(()=>{p(!1),c({value:l,fromUi:!0})},[l,c]),V=W({formId:n})?r.allowFormEnterToSubmit(n):s,v=C&&I>t.breakpoints.hideWidgetDetails,E=i.useCallback(()=>{s&&g(),f(!1)},[s,g]),R=i.useCallback(()=>{f(!0)},[]),z=J({formId:n,maxChars:b,setDirty:p,setUiValue:u,setValueWithSource:c}),L=N(n,g,s,r,d),x=m?.startsWith(":material"),w=x?"lg":"base";return o.jsxs(q,{className:"stTextInput","data-testid":"stTextInput",ref:T,children:[o.jsx(H,{label:e.label,disabled:a,labelVisibility:U(e.labelVisibility?.value),htmlFor:h,children:e.help&&o.jsx($,{children:o.jsx(B,{content:e.help,placement:M.TOP_RIGHT})})}),o.jsx(Z,{value:l??"",placeholder:F,onBlur:E,onFocus:R,onChange:z,onKeyPress:L,"aria-label":e.label,disabled:a,id:h,type:ae(e),autoComplete:e.autocomplete,startEnhancer:m&&o.jsx(_,{"data-testid":"stTextInputIcon",iconValue:m,size:w}),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:{height:t.sizes.minElementHeight,borderLeftWidth:t.sizes.borderWidth,borderRightWidth:t.sizes.borderWidth,borderTopWidth:t.sizes.borderWidth,borderBottomWidth:t.sizes.borderWidth,paddingLeft:m?t.spacing.sm:0}},StartEnhancer:{style:{paddingLeft:0,paddingRight:0,minWidth:t.iconSizes.lg,color:x?t.colors.fadedText60:"inherit"}}}}),v&&o.jsx(O,{dirty:s,value:l??"",maxLength:b,inForm:W({formId:n}),allowEnterToSubmit:V})]})}function S(a,e){return a.getStringValue(e)??null}function X(a){return a.default??null}function ee(a){return a.value??null}function te(a,e,r,d){e.setStringValue(a,r.value,{fromUi:r.fromUi},d)}function ae(a){return a.type===G.Type.PASSWORD?"password":"text"}const pe=i.memo(Q);export{pe as default};
