import{_ as __rest,a as __assign}from"./tslib.es6-bjGg6Bxl.js";import React__default,{useRef,useState,useEffect,useMemo,useId}from"react";import{L as Label}from"./Label.component-6VRtHbKe.js";import{I as Icon}from"./Icon.component-7-ap-6Ys.js";import{F as FormHint}from"./FormHint.component-Dkh3ieaZ.js";var textinputstyles="\n  jn-bg-theme-textinput\n  jn-text-theme-textinput\n  jn-border\n  jn-text-base\n  jn-leading-4\n  jn-px-4\n  jn-h-textinput\n  jn-rounded-3px\n  focus:jn-outline-none\n  focus:jn-ring-2\n  focus:jn-ring-theme-focus\n  disabled:jn-opacity-50\n  autofill:jn-bg-theme-textinput-autofill\n  autofill:jn-text-theme-textinput-autofill\n  peer\n",defaultborderstyles="\n  jn-border-theme-textinput-default\n",invalidstyles="\n  jn-border-theme-error\n",validstyles="\n  jn-border-theme-success\n",withLabelStyles="\n  jn-pt-[1.125rem] \n  jn-pb-1\n",noLabelStyles="\n  jn-py-4\n",wrapperStyles="\n  jn-inline-block\n  jn-relative\n",labelStyles="\n  peer-autofill:jn-text-theme-textinput-autofill-label\n  jn-pointer-events-none\n  jn-top-2\n  jn-left-[0.9375rem]\n",iconcontainerstyles="\n  jn-inline-flex\n  jn-absolute\n  jn-top-[.4rem]\n  jn-right-3\n",disablediconstyles="\n  jn-opacity-50\n",hintStyles="\n  jn-mt-0\n",TextInput=function(a){var b=a.value,c=void 0===b?"":b,d=a.id,e=void 0===d?"":d,f=a.name,g=void 0===f?void 0:f,h=a.placeholder,i=void 0===h?"":h,j=a.disabled,k=void 0!==j&&j,l=a.readOnly,m=a.required,n=a.invalid,o=void 0!==n&&n,p=a.valid,q=void 0!==p&&p,r=a.autoFocus,s=a.className,t=void 0===s?"":s,u=a.autoComplete,v=void 0===u?"off":u,w=a.helptext,x=void 0===w?"":w,y=a.successtext,z=void 0===y?"":y,A=a.errortext,B=void 0===A?"":A,C=a.onChange,D=void 0===C?void 0:C,E=a.onFocus,F=void 0===E?void 0:E,G=a.onBlur,H=void 0===G?void 0:G,I=a.type,J=void 0===I?void 0:I,K=a.label,L=void 0===K?void 0:K,M=a.width,N=void 0===M?"full":M,O=a.wrapperClassName,P=void 0===O?"":O,Q=__rest(a,["value","id","name","placeholder","disabled","readOnly","required","invalid","valid","autoFocus","className","autoComplete","helptext","successtext","errortext","onChange","onFocus","onBlur","type","label","width","wrapperClassName"]),R=function(a){return"string"!=typeof a||0!==a.trim().length},S=useRef(null),T=useState(""),U=T[0],V=T[1],W=useState(!1),X=W[0],Y=W[1],Z=useState(!1),$=Z[0],_=Z[1],aa=useState(!1),ba=aa[0],ca=aa[1];useEffect(function(){document.hasFocus()&&S.current.contains(document.activeElement)&&Y(!0)},[]),useEffect(function(){V(c)},[c]);var da=useMemo(function(){return o||!!(B&&R(B))},[o,B]),ea=useMemo(function(){return q||!!(z&&R(z))},[q,z]);useEffect(function(){_(da)},[da]),useEffect(function(){ca(ea)},[ea]);var fa=e||function(){return"juno-textinput-"+useId()}();return React__default.createElement("div",null,React__default.createElement("span",{className:"\n          juno-textinput-wrapper \n          ".concat(wrapperStyles,"\n          ").concat("auto"==N?"jn-inline-block":"jn-block","\n          ").concat("auto"==N?"jn-w-auto":"jn-w-full","\n          ").concat(P,"\n          ")},React__default.createElement("input",__assign({type:J,name:g,autoComplete:v,value:U,id:fa,ref:S,placeholder:i,disabled:k,readOnly:void 0!==l&&l,autoFocus:void 0!==r&&r,onChange:function(a){V(a.target.value),D&&D(a)},onFocus:function(a){Y(!0),F&&F(a)},onBlur:function(a){Y(!1),H&&H(a)},className:"juno-textinput \n            ".concat(textinputstyles,"\n            ").concat(L?withLabelStyles:noLabelStyles,"\n            ").concat($?"juno-textinput-invalid "+invalidstyles:""," \n            ").concat(ba?"juno-textinput-valid "+validstyles:"","  \n            ").concat(ba||$?"":defaultborderstyles," \n            ").concat("auto"==N?"jn-w-auto":"jn-w-full","\n            ").concat(t,"\n          ")},Q)),L&&L.length?(React__default.createElement(Label,{text:L,htmlFor:fa,className:"".concat(labelStyles),disabled:k,required:void 0!==m&&m,floating:!0,minimized:!!(i||X||U&&R(U))})):"",React__default.createElement(function(a){var b=a.disabled;return ba||$?(React__default.createElement("div",{className:"juno-textinput-row-icon-container ".concat(iconcontainerstyles," ").concat(b?disablediconstyles:"")},$?React__default.createElement(Icon,{icon:"dangerous",color:"jn-text-theme-error"}):null,ba?React__default.createElement(Icon,{icon:"checkCircle",color:"jn-text-theme-success"}):null)):""},{disabled:k})),B&&R(B)?(React__default.createElement(FormHint,{text:B,variant:"error",className:"".concat(hintStyles)})):"",z&&R(z)?(React__default.createElement(FormHint,{text:z,variant:"success",className:"".concat(hintStyles)})):"",x&&R(x)?React__default.createElement(FormHint,{text:x,className:"".concat(hintStyles)}):"")};export{TextInput as T};