import { jsx as _jsx } from "react/jsx-runtime";
import { forwardRef, useImperativeHandle, useState, } from "react";
import Input from "../Input";
export function validateEmail(email) {
    return /@.*\./.test(email);
}
function _EmailInput(props, ref) {
    const [localWarning, setLocalWarning] = useState(props.value ? !validateEmail(props.value) : false);
    useImperativeHandle(ref, () => ({
        validateEmail: validateEmail,
    }));
    function _handleInputChange(e) {
        props.onChange(e.target.value, validateEmail(e.target.value));
    }
    return (_jsx(Input, { ...props, error: localWarning ? props.messages.invalidEmail : props.error, onBlur: ({ target: { value } }) => {
            setLocalWarning(!!value && !validateEmail(value));
        }, onFocus: () => setLocalWarning(false), onChange: _handleInputChange }));
}
/**
 * A Input based wrapper to handle inputs of email
 **/
/**
 * An email input field that validates the email format and shows error messages when the email is invalid.
 **/
const EmailInput = forwardRef(_EmailInput);
export default EmailInput;
//# sourceMappingURL=EmailInput.js.map