"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getHelperText = exports.hasError = void 0;
function getErrors(errors, searchName) {
    if (errors && Object.keys(errors).length > 0) {
        var split = searchName.split(".");
        if (split.length >= 2) {
            var propertyName = split[0];
            if (errors[propertyName] == null || errors[propertyName].length === 0) {
                return "";
            }
            var indexOrName = void 0;
            if (isNaN(parseInt(split[1], 10))) {
                indexOrName = split[1];
            }
            else {
                indexOrName = parseInt(split[1], 10);
            }
            var tempErrors = errors[propertyName][indexOrName];
            var restSearchName = split.slice(2).join(".");
            if (restSearchName === "") {
                return tempErrors;
            }
            else {
                return getErrors(tempErrors, restSearchName);
            }
        }
        else {
            return errors[split[0]];
        }
    }
    else {
        return "";
    }
}
function hasError(name, form, error) {
    var errorString = getErrors(form.errors, name);
    var touched = getErrors(form.touched, name);
    return ((form.errors &&
        touched === true &&
        errorString &&
        errorString.length > 0) ||
        error);
}
exports.hasError = hasError;
function getHelperText(name, form, helperText) {
    var errorString = getErrors(form.errors, name);
    var touched = getErrors(form.touched, name);
    return (form.errors && touched && errorString) || helperText;
}
exports.getHelperText = getHelperText;
