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.paqmDQdB.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.CwaSe4JX.js";import{t as u}from"./useEmotionTheme.tyjAwN1A.js";import{t as d}from"./TextField.XEZpfH-x.js";import{$t as f,_n as p,at as m,nt as ee,pn as h,yn as g}from"./index.BfkDCGNp.js";import{n as _}from"./useBasicWidgetState.Bj6bxpQq.js";import{t as v}from"./InputInstructions.BQ0J8hJM.js";import{n as y,r as b,t as x}from"./useUpdateUiValue.CT93eHPI.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: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(h,{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[h,O]=(0,S.useState)(()=>k(i,t)??null),{width:F,elementRef:I}=f(),[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:l,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,h,O,L);let[U,W]=(0,S.useState)(!1),G=u(),K=(0,S.useId)(),{placeholder:q,formId:J,icon:Y,maxChars:X}=t,Z=t.type===o.Type.PASSWORD,Q=(0,S.useCallback)(()=>{R(!1),H({value:h,fromUi:!0})},[h,H]),$=c({formId:J})?i.allowFormEnterToSubmit(J):L,te=U&&F>a(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,l);return r(C,{className:`stTextInput`,"data-testid":`stTextInput`,ref:I,children:[n(m,{label:t.label,disabled:e,labelVisibility:s(t.labelVisibility?.value),htmlFor:K,children:t.help&&n(ee,{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:g(Y),children:n(p,{"data-testid":`stTextInputIcon`,iconValue:Y,size:`base`})}),n(T,{id:K,"aria-label":t.label,value:h??``,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(p,{iconValue:z?`:material/visibility_off:`:`:material/visibility:`,size:`base`})})]})}),te&&n(v,{dirty:L,value:h??``,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,S.memo)(O);export{F as default};