import "./TextField.css";
import {FieldErrorIcon as $9afd80978c252040$export$bda0d075e0e342c9, FieldGroup as $9afd80978c252040$export$f0fe469072bc6950, FieldLabel as $9afd80978c252040$export$1acdcf5a973a8414, HelpText as $9afd80978c252040$export$a67c0bc59081311a, Input as $9afd80978c252040$export$f5b8910cec6cf069} from "./Field.mjs";
import {FormContext as $9b916426527cebe7$export$c24727297075ec6a, useFormProps as $9b916426527cebe7$export$a6b5be5c6b451665} from "./Form.mjs";
import {useSpectrumContextProps as $5ce63c423902f47d$export$764f6146fadd77f7} from "../icons/useSpectrumContextProps.mjs";
import {jsx as $fsr8S$jsx, jsxs as $fsr8S$jsxs, Fragment as $fsr8S$Fragment} from "react/jsx-runtime";
import {TextField as $fsr8S$TextField, composeRenderProps as $fsr8S$composeRenderProps, InputContext as $fsr8S$InputContext, useSlottedContext as $fsr8S$useSlottedContext, TextAreaContext as $fsr8S$TextAreaContext, TextArea as $fsr8S$TextArea} from "react-aria-components";
import {createContext as $fsr8S$createContext, forwardRef as $fsr8S$forwardRef, useRef as $fsr8S$useRef, useContext as $fsr8S$useContext, useImperativeHandle as $fsr8S$useImperativeHandle} from "react";
import {createFocusableRef as $fsr8S$createFocusableRef} from "@react-spectrum/utils";
import {mergeRefs as $fsr8S$mergeRefs} from "@react-aria/utils";

/*
 * Copyright 2024 Adobe. All rights reserved.
 * This file is licensed to you under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License. You may obtain a copy
 * of the License at http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software distributed under
 * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
 * OF ANY KIND, either express or implied. See the License for the specific language
 * governing permissions and limitations under the License.
 */ 







const $d946f50010ba937f$export$2129e27b3ef0d483 = /*#__PURE__*/ (0, $fsr8S$createContext)(null);
const $d946f50010ba937f$export$2c73285ae9390cec = /*#__PURE__*/ (0, $fsr8S$forwardRef)(function TextField(props, ref) {
    [props, ref] = (0, $5ce63c423902f47d$export$764f6146fadd77f7)(props, ref, $d946f50010ba937f$export$2129e27b3ef0d483);
    return /*#__PURE__*/ (0, $fsr8S$jsx)($d946f50010ba937f$export$d22444a338b6e3c2, {
        ...props,
        ref: ref,
        children: /*#__PURE__*/ (0, $fsr8S$jsx)((0, $9afd80978c252040$export$f5b8910cec6cf069), {})
    });
});
const $d946f50010ba937f$export$2dc6166a7e65358c = /*#__PURE__*/ (0, $fsr8S$createContext)(null);
const $d946f50010ba937f$export$f5c9f3c2c4054eec = /*#__PURE__*/ (0, $fsr8S$forwardRef)(function TextArea(props, ref) {
    [props, ref] = (0, $5ce63c423902f47d$export$764f6146fadd77f7)(props, ref, $d946f50010ba937f$export$2dc6166a7e65358c);
    return /*#__PURE__*/ (0, $fsr8S$jsx)($d946f50010ba937f$export$d22444a338b6e3c2, {
        ...props,
        ref: ref,
        fieldGroupCss: " ea12 Fd12",
        children: /*#__PURE__*/ (0, $fsr8S$jsx)($d946f50010ba937f$var$TextAreaInput, {})
    });
});
const $d946f50010ba937f$export$d22444a338b6e3c2 = /*#__PURE__*/ (0, $fsr8S$forwardRef)(function TextFieldBase(props, ref) {
    let inputRef = (0, $fsr8S$useRef)(null);
    let domRef = (0, $fsr8S$useRef)(null);
    let formContext = (0, $fsr8S$useContext)((0, $9b916426527cebe7$export$c24727297075ec6a));
    props = (0, $9b916426527cebe7$export$a6b5be5c6b451665)(props);
    let { label: label, description: description, errorMessage: errorMessage, necessityIndicator: necessityIndicator, labelPosition: labelPosition = 'top', labelAlign: labelAlign = 'start', fieldGroupCss: fieldGroupCss, UNSAFE_style: UNSAFE_style, UNSAFE_className: UNSAFE_className = '', ...textFieldProps } = props;
    // Expose imperative interface for ref
    (0, $fsr8S$useImperativeHandle)(ref, ()=>({
            ...(0, $fsr8S$createFocusableRef)(domRef, inputRef),
            select () {
                if (inputRef.current) inputRef.current.select();
            },
            getInputElement () {
                return inputRef.current;
            }
        }));
    return /*#__PURE__*/ (0, $fsr8S$jsx)((0, $fsr8S$TextField), {
        ...textFieldProps,
        ref: domRef,
        style: UNSAFE_style,
        className: UNSAFE_className + function anonymous(props, overrides) {
            let rules = " ";
            let gridColumnStart = false;
            let gridColumnEnd = false;
            let matches = (overrides || '').matchAll(/(?:^|\s)(J|G|I|H|_u|_v|_s|__A|_d|_J|z|y|B|A|_P|_9|W|_l|_A|_z|_6|Z|N|L)[^\s]+/g);
            for (let p of matches){
                if (p[1] === "z") gridColumnStart = true;
                if (p[1] === "y") gridColumnEnd = true;
                rules += p[0];
            }
            rules += ' se12';
            if (props.isInForm) {
                if (!gridColumnStart) rules += ' z2mU12';
            }
            if (props.isInForm) {
                if (props.labelPosition === "side") {
                    if (!gridColumnEnd) rules += ' yvoofG12';
                }
            }
            if (props.isInForm) rules += ' DLwlgod12';
            else {
                if (props.labelPosition === "side") rules += ' DPlN5qb12';
                else if (props.labelPosition === "top") rules += ' DM8Mfn12';
            }
            if (props.labelPosition === "side") rules += ' EPlN5qb12';
            else if (props.labelPosition === "top") rules += ' E4w1sLc12';
            if (props.labelPosition === "side") rules += ' CbRM95c12';
            else if (props.labelPosition === "top") rules += ' Cxaocre12';
            if (props.size === "XL") {
                rules += ' -_6BNtrc-e12';
                rules += ' vx12';
            } else if (props.size === "L") {
                rules += ' -_6BNtrc-d12';
                rules += ' vx12';
            } else if (props.size === "S") {
                rules += ' -_6BNtrc-b12';
                rules += ' vx12';
            } else if (props.size === "XS") {
                rules += ' -_6BNtrc-a12';
                rules += ' vx12';
            } else {
                rules += ' -_6BNtrc-c12';
                rules += ' vx12';
            }
            rules += ' ea12';
            rules += ' _Fd12';
            rules += ' _FezxGHba12';
            rules += ' _FnuYUweb12';
            if (props.size === "XL") rules += ' -BhX7R-Fz12';
            else if (props.size === "L") rules += ' -BhX7R-Fv12';
            else if (props.size === "S") rules += ' -BhX7R-Fp12';
            else if (props.size === "XS") rules += ' -BhX7R-Fn12';
            else rules += ' -BhX7R-Fx12';
            rules += ' -AJjOLd-UVkF0Db12';
            rules += ' qg12';
            rules += ' __ca12';
            return rules;
        }({
            size: props.size,
            labelPosition: labelPosition,
            isInForm: !!formContext
        }, props.styles),
        children: (0, $fsr8S$composeRenderProps)(props.children, (children, { isDisabled: isDisabled, isInvalid: isInvalid })=>/*#__PURE__*/ (0, $fsr8S$jsxs)((0, $fsr8S$Fragment), {
                children: [
                    /*#__PURE__*/ (0, $fsr8S$jsx)((0, $9afd80978c252040$export$1acdcf5a973a8414), {
                        isDisabled: isDisabled,
                        isRequired: props.isRequired,
                        size: props.size,
                        labelPosition: labelPosition,
                        labelAlign: labelAlign,
                        necessityIndicator: necessityIndicator,
                        contextualHelp: props.contextualHelp,
                        children: label
                    }),
                    /*#__PURE__*/ (0, $fsr8S$jsxs)((0, $9afd80978c252040$export$f0fe469072bc6950), {
                        size: props.size,
                        styles: fieldGroupCss,
                        children: [
                            /*#__PURE__*/ (0, $fsr8S$jsx)((0, $fsr8S$InputContext).Consumer, {
                                children: (ctx)=>/*#__PURE__*/ (0, $fsr8S$jsx)((0, $fsr8S$InputContext).Provider, {
                                        value: {
                                            ...ctx,
                                            ref: (0, $fsr8S$mergeRefs)(ctx?.ref, inputRef)
                                        },
                                        children: children
                                    })
                            }),
                            isInvalid && /*#__PURE__*/ (0, $fsr8S$jsx)((0, $9afd80978c252040$export$bda0d075e0e342c9), {
                                isDisabled: isDisabled
                            })
                        ]
                    }),
                    /*#__PURE__*/ (0, $fsr8S$jsx)((0, $9afd80978c252040$export$a67c0bc59081311a), {
                        size: props.size,
                        isDisabled: isDisabled,
                        isInvalid: isInvalid,
                        description: description,
                        children: errorMessage
                    })
                ]
            }))
    });
});
function $d946f50010ba937f$var$TextAreaInput() {
    // Force re-render when value changes so we update the height.
    let { placeholder: placeholder } = (0, $fsr8S$useSlottedContext)((0, $fsr8S$TextAreaContext)) ?? {};
    let onHeightChange = (input)=>{
        // TODO: only do this if an explicit height is not given?
        if (input) {
            let prevAlignment = input.style.alignSelf;
            let prevOverflow = input.style.overflow;
            // Firefox scroll position is lost when overflow: 'hidden' is applied so we skip applying it.
            // The measure/applied height is also incorrect/reset if we turn on and off
            // overflow: hidden in Firefox https://bugzilla.mozilla.org/show_bug.cgi?id=1787062
            let isFirefox = 'MozAppearance' in input.style;
            if (!isFirefox) input.style.overflow = 'hidden';
            input.style.alignSelf = 'start';
            input.style.height = 'auto';
            // offsetHeight - clientHeight accounts for the border/padding.
            input.style.height = `${input.scrollHeight + (input.offsetHeight - input.clientHeight)}px`;
            input.style.overflow = prevOverflow;
            input.style.alignSelf = prevAlignment;
        }
    };
    let { ref: ref } = (0, $fsr8S$useSlottedContext)((0, $fsr8S$InputContext)) ?? {};
    return /*#__PURE__*/ (0, $fsr8S$jsx)((0, $fsr8S$TextArea), {
        ref: (0, $fsr8S$mergeRefs)(onHeightChange, ref),
        // Workaround for baseline alignment bug in Safari.
        // https://bugs.webkit.org/show_bug.cgi?id=142968
        placeholder: placeholder ?? ' ',
        className: function anonymous(props) {
            let rules = " ";
            rules += ' Sd12';
            rules += ' Rd12';
            rules += ' Tu7Fubd12';
            rules += ' Qu7Fubd12';
            rules += ' MAyFGYc12';
            rules += ' _oa12';
            rules += ' g912';
            rules += ' p40ub4c12';
            rules += ' pYFIK2bn12';
            rules += ' u40ub4c12';
            rules += ' v40ub4c12';
            rules += ' x40ub4c12';
            rules += ' _xa12';
            rules += ' _F40ub4c12';
            rules += ' _ub12';
            rules += ' Na12';
            rules += ' _Le12';
            rules += ' _je12';
            rules += ' _Qc12';
            rules += ' _Nc12';
            if (props.size === "XL") rules += ' -M_-Mk12';
            else if (props.size === "L") rules += ' -M_-Mh12';
            else if (props.size === "S") rules += ' -M_-Mg12';
            else if (props.size === "XS") rules += ' -M_-Mf12';
            else rules += ' -M_-Mi12';
            return rules;
        }
    });
}


export {$d946f50010ba937f$export$2129e27b3ef0d483 as TextFieldContext, $d946f50010ba937f$export$2c73285ae9390cec as TextField, $d946f50010ba937f$export$d22444a338b6e3c2 as TextFieldBase, $d946f50010ba937f$export$2dc6166a7e65358c as TextAreaContext, $d946f50010ba937f$export$f5c9f3c2c4054eec as TextArea};
//# sourceMappingURL=TextField.mjs.map
