import{o as e}from"./rolldown-runtime.DAXXjFlN.js";import{r as t}from"./emotion-is-prop-valid.esm.CygBv61C.js";import{a as n,i as r,t as i}from"./emotion-styled.browser.esm.DsRKNFfx.js";import{Ut as a,Xt as o,c as s}from"./utils.94RcZhG4.js";import{R as c}from"./protobuf.DC2L68b9.js";import{r as l,t as u}from"./DynamicIcon.44zobID_.js";import{t as d}from"./useEmotionTheme.D29Ufy6b.js";import{s as f}from"./Tooltip.PNC8NIZa.js";import{r as p}from"./useTextField.BYQ8oAlv.js";import{t as m}from"./TextField.L8vxRwMe.js";import{t as h}from"./useCalculatedDimensions.BnLCBgVi.js";import{t as ee}from"./WidgetLabel.CVV1ys75.js";import{t as g}from"./WidgetLabelHelpIcon.BmvkC-YW.js";import{n as _}from"./useBasicWidgetState.CpWukz_T.js";import{t as v}from"./InputInstructions.D7oNXsUt.js";import{n as y,r as b,t as x}from"./useUpdateUiValue.9IVpZphL.js";var S=e(t(),1),C=i(`div`,{target:`ef5iutx0`})(`position:relative;`),w=i(`div`,{target:`ef5iutx1`})(({theme:e,$isFocused:t,$hasIcon:n})=>({display:`flex`,alignItems:`center`,height:e.sizes.minElementHeight,borderWidth:e.sizes.borderWidth,borderStyle:`solid`,borderColor:f(e.colors,t),borderRadius:e.radii.default,backgroundColor:e.colors.secondaryBg,paddingLeft:n?e.spacing.sm:0,overflow:`hidden`,transitionDuration:`200ms`,transitionProperty:`border`,transitionTimingFunction:`cubic-bezier(0.2, 0.8, 0.4, 1)`,"&:focus-within":{borderColor:f(e.colors,!0)}})),T=i(p,{target:`ef5iutx2`})(({theme:e})=>({flex:1,minWidth:0,border:`none`,background:`transparent`,outline:`none`,color:e.colors.bodyText,fontFamily:e.genericFonts.bodyFont,fontSize:e.fontSizes.sm,fontWeight:e.fontWeights.normal,lineHeight:e.lineHeights.inputWidget,paddingTop:e.spacing.sm,paddingBottom:e.spacing.sm,paddingLeft:e.spacing.md,paddingRight:e.spacing.sm,"::placeholder":{color:e.colors.fadedText60},"&[disabled]":{cursor:`not-allowed`,color:e.colors.fadedText40,WebkitTextFillColor:e.colors.fadedText40,backgroundColor:`transparent`}})),E=i(`div`,{target:`ef5iutx3`})(({theme:e,$isMaterialIcon:t})=>({display:`flex`,alignItems:`center`,paddingLeft:0,paddingRight:0,minWidth:e.iconSizes.base,color:t?e.colors.fadedText60:`inherit`,flexShrink:0})),D=i(`button`,{target:`ef5iutx4`})(({theme:e})=>({display:`flex`,alignItems:`center`,background:`none`,border:`none`,cursor:`pointer`,padding:`0 ${e.spacing.sm}`,color:e.colors.bodyText,flexShrink:0,"&:hover:not(:disabled)":{opacity:.7},"&:disabled":{cursor:`not-allowed`,color:e.colors.fadedText40},"&:focus-visible":{outline:`none`,borderRadius:e.radii.default,boxShadow:`inset ${e.shadows.focusRing}`}}));function O({disabled:e,element:t,widgetMgr:i,fragmentId:f}){let[p,O]=(0,S.useState)(()=>k(i,t)??null),{width:F,elementRef:I}=h(),[L,R]=(0,S.useState)(!1),[z,B]=(0,S.useState)(!1),[V,H]=_({getStateFromWidgetMgr:k,getDefaultStateFromProto:A,getCurrStateFromProto:j,updateWidgetMgrState:M,element:t,widgetMgr:i,fragmentId:f,formClearBehavior:`resetValueAndRunCallback`,onFormCleared:(0,S.useCallback)(()=>{O(t.default??null),R(!0)},[t.default]),queryParamBinding:t.queryParamKey?{paramKey:t.queryParamKey,valueType:`string_value`,clearable:!0}:void 0});x(V,p,O,L);let[U,W]=(0,S.useState)(!1),G=d(),K=(0,S.useId)(),{placeholder:q,formId:J,icon:Y,maxChars:X}=t,Z=t.type===c.Type.PASSWORD,Q=(0,S.useCallback)(()=>{R(!1),H({value:p,fromUi:!0})},[p,H]),$=a({formId:J})?i.allowFormEnterToSubmit(J):L,te=U&&F>s(G.breakpoints.hideWidgetDetails),ne=(0,S.useCallback)(()=>{W(!0)},[]),re=(0,S.useCallback)(e=>{if(I.current?.contains(e.relatedTarget)){W(!1);return}L&&Q(),W(!1)},[L,Q,I]),ie=(0,S.useCallback)(()=>{B(e=>!e)},[]),ae=b({formId:J,maxChars:X,setDirty:R,setUiValue:O,setValueWithSource:H}),oe=y(J,Q,L,i,f);return n(C,{className:`stTextInput`,"data-testid":`stTextInput`,ref:I,children:[r(ee,{label:t.label,disabled:e,labelVisibility:o(t.labelVisibility?.value),htmlFor:K,children:t.help&&r(g,{content:t.help,label:t.label})}),r(m,{isDisabled:e,children:n(w,{"data-testid":`stTextInputRootElement`,$isFocused:U,$hasIcon:!!Y,children:[Y&&r(E,{$isMaterialIcon:l(Y),children:r(u,{"data-testid":`stTextInputIcon`,iconValue:Y,size:`base`})}),r(T,{id:K,"aria-label":t.label,value:p??``,placeholder:q,type:z?`text`:N(t),autoComplete:t.autocomplete,onFocus:ne,onBlur:re,onChange:ae,onKeyDown:oe}),Z&&r(D,{type:`button`,onMouseDown:P,onClick:ie,"aria-label":z?`Hide password`:`Show password`,"aria-pressed":z,disabled:e,children:r(u,{iconValue:z?`:material/visibility_off:`:`:material/visibility:`,size:`base`})})]})}),te&&r(v,{dirty:L,value:p??``,maxLength:X,inForm:a({formId:J}),allowEnterToSubmit:$})]})}function k(e,t){return e.getStringValue(t)??null}function A(e){return e.default??null}function j(e){return e.value??null}function M(e,t,n,r){t.setStringValue(e,n.value,{fromUi:n.fromUi},r)}function N(e){return e.type===c.Type.PASSWORD?`password`:`text`}function P(e){e.preventDefault()}var F=(0,S.memo)(O);export{F as default};