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