// formSubmitValidation will be deprecated. use "validateControls" instead.
// TODO: Improve the way we mark components with error. We must not use error classes.
const formElementsErrorClassesDictionary = {
    "ch-checkbox": "checkbox-error",
    "ch-combo-box-render": "combo-box-error",
    "ch-edit": "input-error"
};
const toggleErrorClass = (hasError, element) => {
    const elementTagName = element.tagName.toLowerCase();
    const errorClass = formElementsErrorClassesDictionary[elementTagName];
    if (hasError) {
        element.classList.add(errorClass);
    }
    else {
        element.classList.remove(errorClass);
    }
};
const validateControls = (formSubmitResult, validatableControls) => {
    const validatableControlsUpdated = new Map(validatableControls);
    formSubmitResult.fieldErrors.forEach(fieldResult => {
        const fieldKey = fieldResult.key;
        const fieldHasError = fieldResult.hasError;
        const controlMapRecord = validatableControlsUpdated.get(fieldKey);
        if (controlMapRecord === null || controlMapRecord === void 0 ? void 0 : controlMapRecord.reference) {
            // toggle class to add or remove error style
            toggleErrorClass(fieldHasError, controlMapRecord.reference);
            validatableControlsUpdated.set(fieldKey, Object.assign(Object.assign({}, controlMapRecord), { hasError: fieldHasError, message: fieldResult.message }));
        }
    });
    // return validatableControls updated.
    return validatableControlsUpdated;
};
const clearControlError = (validatableControls, controlId) => {
    const control = validatableControls.get(controlId);
    if (control === null || control === void 0 ? void 0 : control.reference) {
        toggleErrorClass(false, control.reference);
        control.hasError = false;
        control.message = "";
        validatableControls.set(controlId, control);
    }
};

export { clearControlError as c, validateControls as v };

//# sourceMappingURL=form-validation-21ab3766.js.map