import{n as R,r as o,a0 as U,ca as I,am as k,j as u,bc as z,bp as H,bd as L,aY as B,be as D,cc as j}from"./index.BSITpAz8.js";import{u as O}from"./uniqueId.BNjI9ROI.js";import{u as _,a as K,b as q}from"./useOnInputChange.B1QB2TNw.js";import{a as A}from"./useBasicWidgetState.B8IH-5cn.js";import{I as G}from"./InputInstructions.CWlmC2Qh.js";import{I as N}from"./input.qSadM7Tx.js";import"./inputUtils.CQWz5UKz.js";import"./FormClearHelper.Tmz_sTQ8.js";import"./base-input.C7heAUz7.js";const Y=R("div",{target:"e1sommdr0"})(({width:e})=>({position:"relative",width:e}));function rt({disabled:e,element:t,widgetMgr:s,width:n,fragmentId:m}){var g;const[r,l]=o.useState(S(s,t)??null),[i,d]=o.useState(!1),W=o.useCallback(()=>{l(t.default??null),d(!0)},[t.default]),[y,c]=A({getStateFromWidgetMgr:S,getDefaultStateFromProto:$,getCurrStateFromProto:w,updateWidgetMgrState:J,element:t,widgetMgr:s,fragmentId:m,onFormCleared:W});_(y,r,l,i);const[T,h]=o.useState(!1),a=U(),[f]=o.useState(()=>O("text_input_")),{placeholder:x,formId:b}=t,p=o.useCallback(()=>{d(!1),c({value:r,fromUi:!0})},[r,c]),C=I({formId:b})?s.allowFormEnterToSubmit(b):i,V=T&&n>a.breakpoints.hideWidgetDetails,F=o.useCallback(()=>{i&&p(),h(!1)},[i,p]),v=o.useCallback(()=>{h(!0)},[]),E=K({formId:t.formId,maxChars:t.maxChars,setDirty:d,setUiValue:l,setValueWithSource:c}),P=q(t.formId,p,i,s,m);return k(Y,{className:"stTextInput","data-testid":"stTextInput",width:n,children:[u(D,{label:t.label,disabled:e,labelVisibility:z((g=t.labelVisibility)==null?void 0:g.value),htmlFor:f,children:t.help&&u(H,{children:u(L,{content:t.help,placement:B.TOP_RIGHT})})}),u(N,{value:r??"",placeholder:x,onBlur:F,onFocus:v,onChange:E,onKeyPress:P,"aria-label":t.label,disabled:e,id:f,type:Q(t),autoComplete:t.autocomplete,overrides:{Input:{style:{minWidth:0,"::placeholder":{opacity:"0.7"},lineHeight:a.lineHeights.inputWidget,paddingRight:a.spacing.sm,paddingLeft:a.spacing.sm,paddingBottom:a.spacing.sm,paddingTop:a.spacing.sm}},Root:{props:{"data-testid":"stTextInputRootElement"},style:{height:a.sizes.minElementHeight,borderLeftWidth:a.sizes.borderWidth,borderRightWidth:a.sizes.borderWidth,borderTopWidth:a.sizes.borderWidth,borderBottomWidth:a.sizes.borderWidth}}}}),V&&u(G,{dirty:i,value:r??"",maxLength:t.maxChars,inForm:I({formId:t.formId}),allowEnterToSubmit:C})]})}function S(e,t){return e.getStringValue(t)??null}function $(e){return e.default??null}function w(e){return e.value??null}function J(e,t,s,n){t.setStringValue(e,s.value,{fromUi:s.fromUi},n)}function Q(e){return e.type===j.Type.PASSWORD?"password":"text"}export{rt as default};
