import{f as q,r as a,m as D,o as U,ak as W,O as j,h as K,j as l,q as H,al as _,aj as O,$ as A,am as $}from"./index.RuhrnD1v.js";import{I as w}from"./InputInstructions.BuiQHvdK.js";import{W as N}from"./WidgetLabel.CgwydhVR.js";import{W as G}from"./WidgetLabelHelpIcon.BKLcvqEy.js";import{u as J}from"./useBasicWidgetState.CI9LlGGe.js";import{u as M,a as Q,b as X}from"./useUpdateUiValue.CyB9OGUj.js";import{u as Y}from"./uniqueId.HT2UodMD.js";import{I as Z}from"./input.edoqeH9S.js";import"./styled-components.CXqQ-NdV.js";import"./FormClearHelper.DFo50Lfo.js";import"./inputUtils.CptNuJwn.js";import"./base-input.DmvIDeb9.js";import"./constants.BZvTtNRL.js";const tt=q("div",{target:"eiqkja70"})("position:relative;");function et({disabled:o,element:t,widgetMgr:r,fragmentId:u}){const[s,p]=a.useState(()=>I(r,t)??null),{width:S,elementRef:T}=D(),[i,m]=a.useState(!1),x=a.useCallback(()=>{p(t.default??null),m(!0)},[t.default]),C=t.queryParamKey?{paramKey:t.queryParamKey,valueType:"string_value",clearable:!0}:void 0,[v,h]=J({getStateFromWidgetMgr:I,getDefaultStateFromProto:ot,getCurrStateFromProto:at,updateWidgetMgrState:rt,element:t,widgetMgr:r,fragmentId:u,formClearBehavior:"resetValueAndRunCallback",onFormCleared:x,queryParamBinding:C});M(v,s,p,i);const[V,g]=a.useState(!1),e=U(),[b]=a.useState(()=>Y("text_input_")),{placeholder:F,formId:n,icon:d,maxChars:y}=t,f=a.useCallback(()=>{m(!1),h({value:s,fromUi:!0})},[s,h]),E=W({formId:n})?r.allowFormEnterToSubmit(n):i,R=V&&S>j(e.breakpoints.hideWidgetDetails),P=a.useCallback(()=>{i&&f(),g(!1)},[i,f]),k=a.useCallback(()=>{g(!0)},[]),B=Q({formId:n,maxChars:y,setDirty:m,setUiValue:p,setValueWithSource:h}),L=X(n,f,i,r,u);return K(tt,{className:"stTextInput","data-testid":"stTextInput",ref:T,children:[l(N,{label:t.label,disabled:o,labelVisibility:H(t.labelVisibility?.value),htmlFor:b,children:t.help&&l(G,{content:t.help,label:t.label})}),l(Z,{value:s??"",placeholder:F,onBlur:P,onFocus:k,onChange:B,onKeyPress:L,"aria-label":t.label,disabled:o,id:b,type:it(t),autoComplete:t.autocomplete,startEnhancer:d&&l(A,{"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:z})=>{const c=O(e.colors,z);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"}}}}),R&&l(w,{dirty:i,value:s??"",maxLength:y,inForm:W({formId:n}),allowEnterToSubmit:E})]})}function I(o,t){return o.getStringValue(t)??null}function ot(o){return o.default??null}function at(o){return o.value??null}function rt(o,t,r,u){t.setStringValue(o,r.value,{fromUi:r.fromUi},u)}function it(o){return o.type===$.Type.PASSWORD?"password":"text"}const Wt=a.memo(et);export{Wt as default};
