"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../../_virtual/jsx-runtime.js"),i=require("react"),H=require("../../../icons/AlertCircle.js"),z=require("../../../utils/index.js"),t=require("../styles.js"),D=require("../utils.js"),m=require("./styles.js");function G({autoComplete:v=!1,id:E,name:x,label:r,value:o,type:y="text",placeholder:C,hasError:u=!1,errorText:g,assistText:d,optionalText:F="Optional",disabled:s=!1,variant:L="medium",required:S=!0,maxChar:R,minChar:T,showCharCount:B=!1,width:w,prefix:l,suffix:c,onSuffixClick:h,onChange:I,touched:j,onBlur:M,onFocus:P,onPaste:$,onKeyUp:A,...p},O){const[W,q]=i.useState(0),[a,_]=i.useState(!1);i.useEffect(()=>{o&&typeof o=="string"&&q(o.length)},[]),i.useEffect(()=>{_(typeof j>"u"?u:u&&j)},[u,j]);function k(f){q(f.target.value.length),I(f)}const n=z.getId(p["data-testid"]);return e.jsxRuntimeExports.jsxs(t.Wrapper,{"data-testid":n("text-field"),width:w,children:[e.jsxRuntimeExports.jsxs(t.LabelWrapper,{disabled:s,hasLabel:!!(r!=null&&r.length),children:[r&&e.jsxRuntimeExports.jsx(t.Label,{htmlFor:E||`input-${x}`,disabled:s,children:r}),!S&&!B&&e.jsxRuntimeExports.jsx(t.Text,{children:F}),B&&e.jsxRuntimeExports.jsx(t.Text,{"data-testid":n("char-count"),children:D.getCharacterCount(W,R)})]}),e.jsxRuntimeExports.jsxs(t.Border,{hasError:a,disabled:s,hasPrefix:!!l,hasSuffix:!!c,children:[!!l&&e.jsxRuntimeExports.jsx(m.Prefix,{"data-testid":n("prefix"),children:l}),e.jsxRuntimeExports.jsx(m.TextFieldInput,{hasError:a,ref:O,id:E||`input-${x}`,type:y,variant:L,disabled:s,placeholder:C,autoComplete:v?"on":"off",maxLength:R,minLength:T,value:String(o),onChange:k,onKeyUp:A,onBlur:M,onFocus:P,onPaste:$,"data-trackid":p["data-trackid"],"data-testid":n(),"aria-label":p["aria-label"]||r,name:x}),!!c&&e.jsxRuntimeExports.jsx(m.Sufix,{"data-testid":n("suffix"),hasHandler:!!h,onClick:h&&h,children:c})]}),e.jsxRuntimeExports.jsxs(t.SupportingText,{children:[!!g&&a&&!s&&e.jsxRuntimeExports.jsxs(t.ErrorMessage,{children:[e.jsxRuntimeExports.jsx(H.default,{width:20,height:20}),g]}),!a&&(typeof d=="string"?e.jsxRuntimeExports.jsx(t.AssistMessage,{children:d}):d)]})]})}const J=i.forwardRef(G);exports.TextField=J;
