/**
 * @internal
 * @remarks \@since 2.5.0
 */ const VALIDITY_STATE_KEYS = [
    "badInput",
    "customError",
    "patternMismatch",
    "rangeOverflow",
    "rangeUnderflow",
    "stepMismatch",
    "tooLong",
    "tooShort",
    "typeMismatch",
    "valueMissing"
];
/**
 * @internal
 * @remarks \@since 2.5.0
 */ export const RECOMMENDED_STATE_KEYS = [
    "badInput",
    "tooLong",
    "valueMissing"
];
/**
 * @internal
 * @remarks \@since 2.5.0
 */ export const RECOMMENDED_NUMBER_STATE_KEYS = [
    ...RECOMMENDED_STATE_KEYS,
    "rangeOverflow",
    "rangeUnderflow",
    "tooShort",
    "typeMismatch"
];
/**
 * The validation message is actually kind of weird since it's possible for a
 * form element to have multiple errors at once. The validation message will be
 * the first error that appears, so need to make sure that the first error is
 * one of the recommended state keys so the message appears for only those types
 * of errors.
 *
 * @internal
 * @remarks \@since 2.5.0
 */ const isRecommended = (validity, isNumber)=>{
    const errorable = isNumber ? RECOMMENDED_NUMBER_STATE_KEYS : RECOMMENDED_STATE_KEYS;
    return VALIDITY_STATE_KEYS.every((key)=>{
        const errored = validity[key];
        return !errored || errorable.includes(key);
    });
};
/**
 * The default implementation for getting an error message for the `TextField`
 * or `TextArea` components that relies on the behavior of the
 * {@link ChangeValidationBehavior}
 *
 * @remarks \@since 2.5.0
 */ export const defaultGetErrorMessage = (options)=>{
    const { isNumber, isBlurEvent, validity, validationMessage, validationType: validate } = options;
    if (isBlurEvent || !validationMessage || validate === "change") {
        return validationMessage;
    }
    if (validate === "blur") {
        return "";
    }
    if (validate === "recommended") {
        return isRecommended(validity, isNumber) ? validationMessage : "";
    }
    const keys = typeof validate === "string" ? [
        validate
    ] : validate;
    return keys.length && VALIDITY_STATE_KEYS.some((key)=>validity[key] && keys.includes(key)) ? validationMessage : "";
};
/**
 * The default implementation for checking if a `TextField` or `TextArea` is
 * errored by returning `true` if the `errorMessage` string is truthy or the
 * value is not within the `minLength` and `maxLength` constraints when they
 * exist.
 *
 * @remarks \@since 2.5.0
 */ export const defaultIsErrored = (options)=>{
    const { value, errorMessage, minLength, maxLength, isBlurEvent } = options;
    return !!errorMessage || typeof maxLength === "number" && value.length > maxLength || isBlurEvent && typeof minLength === "number" && value.length < minLength;
};
/**
 * The default implementation for showing an error icon in `TextField` and
 * `TextArea` components that will only display when the error flag is enabled.
 *
 * @remarks \@since 2.5.0
 */ export const defaultGetErrorIcon = (options)=>{
    const { error, errorIcon } = options;
    return error && errorIcon;
};

//# sourceMappingURL=validation.js.map