"use strict";const n=require("react/jsx-runtime"),s=require("react"),k=require("./button-ChYUPi2k.js"),z=require("./field-error-text-FhQulSV5.js"),H=require("./field-helper-text-DSKO-Tce.js"),B=require("./check-circle-filled.es-5-GXE9l4.js"),M=require("./close.es-VL3lKi1O.js"),S=require("./label-yHK80hhV.js"),D=require("./spinner-tKunS_o-.js"),G=require("./bind-DeUYJ6m9.js"),J={"purpur-text-field":"_purpur-text-field_1n0q1_1","purpur-text-field__label":"_purpur-text-field__label_1n0q1_7","purpur-text-field__label-text":"_purpur-text-field__label-text_1n0q1_12","purpur-text-field__field-row":"_purpur-text-field__field-row_1n0q1_15","purpur-text-field__frame":"_purpur-text-field__frame_1n0q1_19","purpur-text-field__frame--negative":"_purpur-text-field__frame--negative_1n0q1_26","purpur-text-field__input-container":"_purpur-text-field__input-container_1n0q1_29","purpur-text-field__input-container--disabled":"_purpur-text-field__input-container--disabled_1n0q1_40","purpur-text-field__input-container--readonly":"_purpur-text-field__input-container--readonly_1n0q1_43","purpur-text-field__input-container--has-clear-button":"_purpur-text-field__input-container--has-clear-button_1n0q1_46","purpur-text-field__input-container--end-adornment":"_purpur-text-field__input-container--end-adornment_1n0q1_49","purpur-text-field__input":"_purpur-text-field__input_1n0q1_29","purpur-text-field__input-container--start-adornment":"_purpur-text-field__input-container--start-adornment_1n0q1_55","purpur-text-field__input-container--negative":"_purpur-text-field__input-container--negative_1n0q1_61","purpur-text-field__input--valid":"_purpur-text-field__input--valid_1n0q1_109","purpur-text-field__input--error":"_purpur-text-field__input--error_1n0q1_109","purpur-text-field__input--negative":"_purpur-text-field__input--negative_1n0q1_130","purpur-text-field__adornment-container":"_purpur-text-field__adornment-container_1n0q1_146","purpur-text-field__valid-icon":"_purpur-text-field__valid-icon_1n0q1_151","purpur-text-field__valid-icon--negative":"_purpur-text-field__valid-icon--negative_1n0q1_154"},K=d=>s.useRef(d),_=G.c.bind(J),e="purpur-text-field",m=s.forwardRef(({["data-testid"]:d,className:R,clearButtonAriaLabel:b,beforeField:q,afterField:v,endAdornment:p,errorText:l,helperText:h,hideRequiredAsterisk:C=!1,label:$,loading:j=!1,onClear:y,startAdornment:I,valid:T=!1,negative:i=!1,...t},u)=>{const w=s.useId(),c=t.id??w,r=a=>d?`${d}-${a}`:void 0,N=T&&!l,o=h?`${c}-helper-text`:void 0,x=[I].filter(a=>!!a),g=(typeof t.value=="number"?t.value!==void 0:t.value?.length)&&!t.disabled&&!t.readOnly&&!j&&y&&b,F=K(null),E=a=>{F.current=a,typeof u=="function"?u(a):u&&(u.current=a)},O=()=>{y?.(),F.current?.focus()},f=[j&&n.jsx(D.Spinner,{disabled:t.disabled,size:"xs","data-testid":r("spinner"),negative:i},"spinner"),g&&n.jsx(k.Button,{negative:i,variant:"tertiary-purple",onClick:O,iconOnly:!0,"aria-label":b??"","data-testid":r("clear-button"),tabIndex:-1,children:n.jsx(M.r,{size:"xs"})},"clear-button"),N&&n.jsx(B.r,{"data-testid":r("valid-icon"),className:_(`${e}__valid-icon`,{[`${e}__valid-icon--negative`]:i})},"valid-icon")].filter(a=>!!a),V=_(`${e}__input-container`,{[`${e}__input-container--start-adornment`]:x.length,[`${e}__input-container--end-adornment`]:f.length||p,[`${e}__input-container--disabled`]:t.disabled,[`${e}__input-container--has-clear-button`]:g,[`${e}__input-container--readonly`]:t.readOnly&&!t.disabled,[`${e}__input-container--negative`]:i});return n.jsxs("div",{className:_(R,e),children:[$&&n.jsxs(S.Label,{htmlFor:c,className:_(`${e}__label`),"data-testid":r("label"),disabled:t.disabled,negative:i,children:[t.required&&!C&&n.jsx("span",{"aria-hidden":!0,children:"*"}),$]}),n.jsxs("div",{className:_(`${e}__field-row`),children:[!!q&&q,n.jsxs("div",{className:V,children:[!!x.length&&n.jsx("div",{"data-testid":r("start-adornments"),className:_(`${e}__adornment-container`),children:x}),n.jsx("input",{...t,id:c,ref:E,"data-testid":r("input"),"aria-describedby":t["aria-describedby"]||o,"aria-invalid":t["aria-invalid"]||!!l,className:_([`${e}__input`,{[`${e}__input--valid`]:N,[`${e}__input--error`]:!!l,[`${e}__input--negative`]:i}])}),n.jsx("div",{className:_(`${e}__frame`,{[`${e}__frame--negative`]:i})}),(!!f.length||p)&&n.jsxs("div",{"data-testid":r("end-adornments"),className:_(`${e}__adornment-container`),children:[f,p]})]}),!!v&&v]}),o&&n.jsx(H.FieldHelperText,{"data-testid":r("helper-text"),id:o,negative:i,disabled:t.disabled,children:h}),l&&n.jsx(z.FieldErrorText,{"data-testid":r("error-text"),negative:i,children:l})]})});m.displayName="TextField";const L=d=>s.isValidElement(d)&&d.type.displayName===m.displayName;exports.TextField=m;exports.isTextField=L;
//# sourceMappingURL=text-field-B8a-NKm4.js.map
