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.C7ab1lZK.js";import{Jt as a,Vt as o,c as s}from"./utils.KTqwHXHU.js";import{z as c}from"./protobuf.CBn3jIav.js";import{r as l,t as u}from"./DynamicIcon.C4mhYDxF.js";import{t as d}from"./useEmotionTheme.BIIZ9T_O.js";import{a as f}from"./Tooltip.DJg7muty.js";import{n as p}from"./Input.DOzmK8T4.js";import{t as m}from"./TextField.B39H9XTf.js";import{t as h}from"./useCalculatedDimensions.BnLCBgVi.js";import{t as ee}from"./WidgetLabel.B3OAjMbS.js";import{t as g}from"./WidgetLabelHelpIcon.DPIlnvoY.js";import{n as _}from"./useBasicWidgetState.CCuiA4s6.js";import{t as v}from"./InputInstructions.BT3kDpbi.js";import{n as y,r as b,t as x}from"./useUpdateUiValue.BWe0Q6sA.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]),$=o({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:a(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:o({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};