import{n as z,r as a,bh as U,y as k,cr as g,B,j as u,br as H,bF as L,bs as D,ba as j,bt as O,cs as _}from"./index.DmrHunjf.js";import{u as w}from"./uniqueId.CGzhDnjp.js";import{u as K,a as $,b as q}from"./useOnInputChange.CteCxi4o.js";import{a as A}from"./useBasicWidgetState.Qz7AufmX.js";import{I as G}from"./InputInstructions.BsK7vJnF.js";import{I as N}from"./input.Bue7SzO_.js";import"./inputUtils.CQWz5UKz.js";import"./FormClearHelper.CDiPqtGN.js";import"./base-input.Obq7JAg5.js";const J=z("div",{target:"e1o1zy6o0"})("position:relative;");function Q({disabled:e,element:t,widgetMgr:s,fragmentId:n}){var b;const[r,l]=a.useState(I(s,t)??null),[S,W]=U(),[i,d]=a.useState(!1),y=a.useCallback(()=>{l(t.default??null),d(!0)},[t.default]),[T,c]=A({getStateFromWidgetMgr:I,getDefaultStateFromProto:X,getCurrStateFromProto:Y,updateWidgetMgrState:Z,element:t,widgetMgr:s,fragmentId:n,onFormCleared:y});K(T,r,l,i);const[x,m]=a.useState(!1),o=k(),[h]=a.useState(()=>w("text_input_")),{placeholder:C,formId:f}=t,p=a.useCallback(()=>{d(!1),c({value:r,fromUi:!0})},[r,c]),F=g({formId:f})?s.allowFormEnterToSubmit(f):i,V=x&&S>o.breakpoints.hideWidgetDetails,v=a.useCallback(()=>{i&&p(),m(!1)},[i,p]),E=a.useCallback(()=>{m(!0)},[]),P=$({formId:t.formId,maxChars:t.maxChars,setDirty:d,setUiValue:l,setValueWithSource:c}),R=q(t.formId,p,i,s,n);return B(J,{className:"stTextInput","data-testid":"stTextInput",ref:W,children:[u(O,{label:t.label,disabled:e,labelVisibility:H((b=t.labelVisibility)==null?void 0:b.value),htmlFor:h,children:t.help&&u(L,{children:u(D,{content:t.help,placement:j.TOP_RIGHT})})}),u(N,{value:r??"",placeholder:C,onBlur:v,onFocus:E,onChange:P,onKeyPress:R,"aria-label":t.label,disabled:e,id:h,type:M(t),autoComplete:t.autocomplete,overrides:{Input:{style:{minWidth:0,"::placeholder":{opacity:"0.7"},lineHeight:o.lineHeights.inputWidget,paddingRight:o.spacing.sm,paddingLeft:o.spacing.sm,paddingBottom:o.spacing.sm,paddingTop:o.spacing.sm}},Root:{props:{"data-testid":"stTextInputRootElement"},style:{height:o.sizes.minElementHeight,borderLeftWidth:o.sizes.borderWidth,borderRightWidth:o.sizes.borderWidth,borderTopWidth:o.sizes.borderWidth,borderBottomWidth:o.sizes.borderWidth}}}}),V&&u(G,{dirty:i,value:r??"",maxLength:t.maxChars,inForm:g({formId:t.formId}),allowEnterToSubmit:F})]})}function I(e,t){return e.getStringValue(t)??null}function X(e){return e.default??null}function Y(e){return e.value??null}function Z(e,t,s,n){t.setStringValue(e,s.value,{fromUi:s.fromUi},n)}function M(e){return e.type===_.Type.PASSWORD?"password":"text"}const lt=a.memo(Q);export{lt as default};
