import{n as L,r as o,M as R,bZ as I,a8 as U,j as u,a$ as k,bc as z,b0 as H,aL as B,b1 as D,b$ as j}from"./index.DXat8gQf.js";import{u as O}from"./uniqueId.Dme_RYod.js";import{u as _,a as $,b as K}from"./useOnInputChange.8aWa7n-i.js";import{a as q}from"./useBasicWidgetState.BrxTjxxP.js";import{I as w}from"./InputInstructions.BohKIZFT.js";import{I as A}from"./input.CXSAsjSZ.js";import"./inputUtils.CQWz5UKz.js";import"./FormClearHelper.DWef4hWz.js";import"./base-input.CTx0gvzT.js";const G=L("div",{target:"e6m0wlp0"})(({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,p]=q({getStateFromWidgetMgr:S,getDefaultStateFromProto:N,getCurrStateFromProto:Z,updateWidgetMgrState:J,element:t,widgetMgr:s,fragmentId:m,onFormCleared:W});_(y,r,l,i);const[T,h]=o.useState(!1),a=R(),[b]=o.useState(()=>O("text_input_")),{placeholder:x,formId:f}=t,c=o.useCallback(()=>{d(!1),p({value:r,fromUi:!0})},[r,p]),C=I({formId:f})?s.allowFormEnterToSubmit(f):i,V=T&&n>a.breakpoints.hideWidgetDetails,F=o.useCallback(()=>{i&&c(),h(!1)},[i,c]),v=o.useCallback(()=>{h(!0)},[]),E=$({formId:t.formId,maxChars:t.maxChars,setDirty:d,setUiValue:l,setValueWithSource:p}),P=K(t.formId,c,i,s,m);return U(G,{className:"stTextInput","data-testid":"stTextInput",width:n,children:[u(D,{label:t.label,disabled:e,labelVisibility:k((g=t.labelVisibility)==null?void 0:g.value),htmlFor:b,children:t.help&&u(z,{children:u(H,{content:t.help,placement:B.TOP_RIGHT})})}),u(A,{value:r??"",placeholder:x,onBlur:F,onFocus:v,onChange:E,onKeyPress:P,"aria-label":t.label,disabled:e,id:b,type:M(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(w,{dirty:i,value:r??"",maxLength:t.maxChars,inForm:I({formId:t.formId}),allowEnterToSubmit:C})]})}function S(e,t){return e.getStringValue(t)??null}function N(e){return e.default??null}function Z(e){return e.value??null}function J(e,t,s,n){t.setStringValue(e,s.value,{fromUi:s.fromUi},n)}function M(e){return e.type===j.Type.PASSWORD?"password":"text"}export{rt as default};
