import{o as e}from"./rolldown-runtime.DAXXjFlN.js";import{r as t}from"./emotion-is-prop-valid.esm.CygBv61C.js";import{c as n,l as r,t as i}from"./emotion-styled.browser.esm.DmHEQgFq.js";import{c as a}from"./utils.Dw3nndTc.js";import{R as o}from"./protobuf.Cj15o6C6.js";import{N as s,T as c}from"./utils.CmclnrwZ.js";import{y as l}from"./StreamlitMarkdown.DgiZKHgf.js";import{t as u}from"./useEmotionTheme.tyjAwN1A.js";import{t as d}from"./TextField.onDcJ3aJ.js";import{Qt as f,at as p,fn as m,gn as h,nt as g,vn as _}from"./index.D3kRk1xg.js";import{n as v}from"./useBasicWidgetState.Bh_1DRpL.js";import{t as y}from"./InputInstructions.DScrKUse.js";import{n as b,r as x,t as S}from"./useUpdateUiValue.CT93eHPI.js";var C=e(t(),1),ee=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:l(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:l(e.colors,!0)}})),T=i(m,{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:l}){let[m,O]=(0,C.useState)(()=>k(i,t)??null),{width:F,elementRef:I}=f(),[L,R]=(0,C.useState)(!1),[z,B]=(0,C.useState)(!1),[V,H]=v({getStateFromWidgetMgr:k,getDefaultStateFromProto:A,getCurrStateFromProto:j,updateWidgetMgrState:M,element:t,widgetMgr:i,fragmentId:l,formClearBehavior:`resetValueAndRunCallback`,onFormCleared:(0,C.useCallback)(()=>{O(t.default??null),R(!0)},[t.default]),queryParamBinding:t.queryParamKey?{paramKey:t.queryParamKey,valueType:`string_value`,clearable:!0}:void 0});S(V,m,O,L);let[U,W]=(0,C.useState)(!1),G=u(),K=(0,C.useId)(),{placeholder:q,formId:J,icon:Y,maxChars:X}=t,Z=t.type===o.Type.PASSWORD,Q=(0,C.useCallback)(()=>{R(!1),H({value:m,fromUi:!0})},[m,H]),$=c({formId:J})?i.allowFormEnterToSubmit(J):L,te=U&&F>a(G.breakpoints.hideWidgetDetails),ne=(0,C.useCallback)(()=>{W(!0)},[]),re=(0,C.useCallback)(e=>{if(I.current?.contains(e.relatedTarget)){W(!1);return}L&&Q(),W(!1)},[L,Q,I]),ie=(0,C.useCallback)(()=>{B(e=>!e)},[]),ae=x({formId:J,maxChars:X,setDirty:R,setUiValue:O,setValueWithSource:H}),oe=b(J,Q,L,i,l);return r(ee,{className:`stTextInput`,"data-testid":`stTextInput`,ref:I,children:[n(p,{label:t.label,disabled:e,labelVisibility:s(t.labelVisibility?.value),htmlFor:K,children:t.help&&n(g,{content:t.help,label:t.label})}),n(d,{isDisabled:e,children:r(w,{"data-testid":`stTextInputRootElement`,$isFocused:U,$hasIcon:!!Y,children:[Y&&n(E,{$isMaterialIcon:_(Y),children:n(h,{"data-testid":`stTextInputIcon`,iconValue:Y,size:`base`})}),n(T,{id:K,"aria-label":t.label,value:m??``,placeholder:q,type:z?`text`:N(t),autoComplete:t.autocomplete,onFocus:ne,onBlur:re,onChange:ae,onKeyDown:oe}),Z&&n(D,{type:`button`,onMouseDown:P,onClick:ie,"aria-label":z?`Hide password`:`Show password`,"aria-pressed":z,disabled:e,children:n(h,{iconValue:z?`:material/visibility_off:`:`:material/visibility:`,size:`base`})})]})}),te&&n(y,{dirty:L,value:m??``,maxLength:X,inForm:c({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===o.Type.PASSWORD?`password`:`text`}function P(e){e.preventDefault()}var F=(0,C.memo)(O);export{F as default};