// #region Imports
// #endregion
const maxAttribute = 'max';
/**
 * Validator that requires the control's value to be less than or equal to the provided number.
 *
 * State:
 * * rangeOverflow
 *
 * @public
 * @param element
 * @returns null if the validation check passes, otherwise an object containing information.
 */
export function maxValidator(element) {
    if (!element.hasAttribute(maxAttribute)) {
        console.warn(`The '${maxAttribute}' attribute of '${element.tagName.toLowerCase()}' is missing in the inner form field element.`);
    }
    if (isEmptyInputValue(element.value) || isEmptyInputValue(element.max)) {
        return null; // don't validate empty values to allow optional controls
    }
    const value = parseFloat(element.value);
    // Controls with NaN values after parsing should be treated as not having a
    // maximum, per the HTML forms spec: https://www.w3.org/TR/html5/forms.html#attr-input-max
    return !isNaN(value) && value > element.max
        ? {
            rangeOverflow: [true, {
                    max: element.max,
                    actual: element.value
                }]
        }
        : null;
}
function isEmptyInputValue(value) {
    return value == null || ((typeof value === 'string' || Array.isArray(value)) && value.length === 0);
}
//# sourceMappingURL=MaxElementValidatorFn.js.map