import{_ as _extends}from"./_rollupPluginBabelHelpers-B5fk9IVe.js";import React__default,{useRef,useState,useEffect,useMemo,useId}from"react";import PropTypes from"prop-types";import{L as Label,F as FormHint}from"./FormHint.component-BPhoMz7f.js";import{I as Icon}from"./Icon.component-BVkaZqpA.js";const wrapperStyles=`
  jn-inline-block
  jn-relative
`,textareastyles=`
  jn-bg-theme-textinput
  jn-text-theme-textinput
  jn-border
  jn-text-base
  jn-leading-4
  jn-px-4
  jn-rounded-3px
  jn-align-top
  focus:jn-outline-none
  focus:jn-ring-2
  focus:jn-ring-theme-focus
  disabled:jn-opacity-50
  disabled:jn-cursor-not-allowed
`,defaultborderstyles=`
  jn-border-theme-textinput-default
`,invalidstyles=`
  jn-border-theme-error
`,validstyles=`
  jn-border-theme-success
`,withLabelStyles=`
  jn-pt-[1.125rem] 
  jn-pb-1
`,noLabelStyles=`
  jn-py-4
`,labelStyles=`
  jn-pointer-events-none
  jn-top-2
  jn-left-[0.9375rem]
  jn-pr-4
  jn-bg-theme-textinput
`,iconcontainerstyles=`
  jn-inline-flex
  jn-absolute
  jn-top-[.4rem]
  jn-right-3
`,disablediconstyles=`
  jn-opacity-50
`,hintStyles=`
  jn-mt-0
`,Textarea=a=>{let{value:c="",id:d="",placeholder:e="",disabled:f=!1,readOnly:g=!1,required:h=!1,invalid:i=!1,valid:j=!1,autoFocus:k=!1,className:l="",autoComplete:m="off",helptext:n="",successtext:o="",errortext:p="",onChange:q=void 0,onFocus:r=void 0,onBlur:s=void 0,label:t=void 0,width:u="full",wrapperClassName:v="",...b}=a;const w=a=>"string"!=typeof a||0!==a.trim().length,x=useRef(),[y,z]=useState(""),[A,B]=useState(!1),[C,D]=useState(!1),[E,F]=useState(!1);useEffect(()=>{document.hasFocus()&&x.current.contains(document.activeElement)&&B(!0)},[]),useEffect(()=>{z(c)},[c]);const G=useMemo(()=>i||!!(p&&w(p)),[i,p]),H=useMemo(()=>j||!!(o&&w(o)),[j,o]);useEffect(()=>{D(G)},[G]),useEffect(()=>{F(H)},[H]);const I=d||(()=>"juno-textarea-"+useId())();return React__default.createElement("div",null,React__default.createElement("div",{className:`
          juno-textarea-wrapper 
          ${wrapperStyles}
          ${"auto"==u?"jn-inline-block":"jn-block"}
          ${"auto"==u?"jn-w-auto":"jn-w-full"}
          ${v}
        `},t&&t.length?React__default.createElement(Label,{text:t,htmlFor:I,className:`${labelStyles}`,disabled:f,required:h,floating:!0,minimized:!!(e||A||y&&y.length)}):"",React__default.createElement("textarea",_extends({name:name,autoComplete:m,value:y,id:I,ref:x,placeholder:e,disabled:f,readOnly:g,autoFocus:k,onChange:a=>{z(a.target.value),q&&q(a)},onFocus:a=>{B(!0),r&&r(a)},onBlur:a=>{B(!1),s&&s(a)},className:`juno-textarea 
            ${textareastyles}
            ${t?withLabelStyles:noLabelStyles}
            ${C?"juno-textarea-invalid "+invalidstyles:""} 
            ${E?"juno-textarea-valid "+validstyles:""}  
            ${E||C?"":defaultborderstyles} 
            ${"auto"==u?"jn-w-auto":"jn-w-full"}
            ${l}
          `},b)),React__default.createElement(a=>{let{disabled:b}=a;return E||C?React__default.createElement("div",{className:`juno-textinput-row-icon-container ${iconcontainerstyles} ${b?disablediconstyles:""}`},C?React__default.createElement(Icon,{icon:"dangerous",color:"jn-text-theme-error"}):null,E?React__default.createElement(Icon,{icon:"checkCircle",color:"jn-text-theme-success"}):null):""},{disabled:f})),p&&w(p)?React__default.createElement(FormHint,{text:p,variant:"error",className:`${hintStyles}`}):"",o&&w(o)?React__default.createElement(FormHint,{text:o,variant:"success",className:`${hintStyles}`}):"",n&&w(n)?React__default.createElement(FormHint,{text:n,className:`${hintStyles}`}):"")};Textarea.propTypes={name:PropTypes.string,label:PropTypes.string,value:PropTypes.oneOfType([PropTypes.string,PropTypes.number]),id:PropTypes.string,placeholder:PropTypes.string,disabled:PropTypes.bool,readOnly:PropTypes.bool,required:PropTypes.bool,invalid:PropTypes.bool,valid:PropTypes.bool,autoFocus:PropTypes.bool,className:PropTypes.string,autoComplete:PropTypes.string,onChange:PropTypes.func,onFocus:PropTypes.func,onBlur:PropTypes.func,helptext:PropTypes.node,successtext:PropTypes.node,errortext:PropTypes.node,width:PropTypes.oneOf(["full","auto"]),wrapperClassName:PropTypes.string};export{Textarea as T};