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 wrapperStyles="\n  jn-inline-block\n  jn-relative\n",textareastyles="\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-rounded-3px\n  jn-align-top\n  focus:jn-outline-none\n  focus:jn-ring-2\n  focus:jn-ring-theme-focus\n  disabled:jn-opacity-50\n  disabled:jn-cursor-not-allowed\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",labelStyles="\n  jn-pointer-events-none\n  jn-top-2\n  jn-left-[0.9375rem]\n  jn-pr-4\n  jn-bg-theme-textinput\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",Textarea=function(a){var b=a.name,c=a.value,d=void 0===c?"":c,e=a.id,f=void 0===e?"":e,g=a.placeholder,h=void 0===g?"":g,i=a.disabled,j=void 0!==i&&i,k=a.readOnly,l=a.required,m=a.invalid,n=void 0!==m&&m,o=a.valid,p=void 0!==o&&o,q=a.autoFocus,r=a.className,s=void 0===r?"":r,t=a.autoComplete,u=void 0===t?"off":t,v=a.helptext,w=void 0===v?"":v,x=a.successtext,y=void 0===x?"":x,z=a.errortext,A=void 0===z?"":z,B=a.onChange,C=void 0===B?void 0:B,D=a.onFocus,E=void 0===D?void 0:D,F=a.onBlur,G=void 0===F?void 0:F,H=a.label,I=void 0===H?void 0:H,J=a.width,K=void 0===J?"full":J,L=a.wrapperClassName,M=void 0===L?"":L,N=__rest(a,["name","value","id","placeholder","disabled","readOnly","required","invalid","valid","autoFocus","className","autoComplete","helptext","successtext","errortext","onChange","onFocus","onBlur","label","width","wrapperClassName"]),O=function(a){return"string"!=typeof a||0!==a.trim().length},P=useRef(null),Q=useState(""),R=Q[0],S=Q[1],T=useState(!1),U=T[0],V=T[1],W=useState(!1),X=W[0],Y=W[1],Z=useState(!1),$=Z[0],_=Z[1];useEffect(function(){document.hasFocus()&&P.current&&P.current.contains(document.activeElement)&&V(!0)},[]),useEffect(function(){S(d.toString())},[d]);var aa=useMemo(function(){return n||!!(A&&O(A))},[n,A]),ba=useMemo(function(){return p||!!(y&&O(y))},[p,y]);useEffect(function(){Y(aa)},[aa]),useEffect(function(){_(ba)},[ba]);var ca=f||function(){return"juno-textarea-"+useId()}();return React__default.createElement("div",null,React__default.createElement("div",{className:"\n          juno-textarea-wrapper \n          ".concat(wrapperStyles,"\n          ").concat("auto"==K?"jn-inline-block":"jn-block","\n          ").concat("auto"==K?"jn-w-auto":"jn-w-full","\n          ").concat(M,"\n        ")},I&&I.length?(React__default.createElement(Label,{text:I,htmlFor:ca,className:"".concat(labelStyles),disabled:j,required:void 0!==l&&l,floating:!0,minimized:!!(h||U||R&&R.length)})):"",React__default.createElement("textarea",__assign({name:b,autoComplete:u,value:R,id:ca,ref:P,placeholder:h,disabled:j,readOnly:void 0!==k&&k,autoFocus:void 0!==q&&q,onChange:function(a){S(a.target.value),C&&C(a)},onFocus:function(a){V(!0),E&&E(a)},onBlur:function(a){V(!1),G&&G(a)},className:"juno-textarea \n            ".concat(textareastyles,"\n            ").concat(I?withLabelStyles:noLabelStyles,"\n            ").concat(X?"juno-textarea-invalid "+invalidstyles:""," \n            ").concat($?"juno-textarea-valid "+validstyles:"","  \n            ").concat($||X?"":defaultborderstyles," \n            ").concat("auto"==K?"jn-w-auto":"jn-w-full","\n            ").concat(s,"\n          ")},N)),React__default.createElement(function(a){var b=a.disabled;return $||X?(React__default.createElement("div",{className:"juno-textinput-row-icon-container ".concat(iconcontainerstyles," ").concat(b?disablediconstyles:"")},X?React__default.createElement(Icon,{icon:"dangerous",color:"jn-text-theme-error"}):null,$?React__default.createElement(Icon,{icon:"checkCircle",color:"jn-text-theme-success"}):null)):""},{disabled:j})),A&&O(A)?(React__default.createElement(FormHint,{text:A,variant:"error",className:"".concat(hintStyles)})):"",y&&O(y)?(React__default.createElement(FormHint,{text:y,variant:"success",className:"".concat(hintStyles)})):"",w&&O(w)?React__default.createElement(FormHint,{text:w,className:"".concat(hintStyles)}):"")};export{Textarea as T};