var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
import { Injectable } from '@angular/core';
import { Validators } from '@angular/forms';
import { Constants } from '../../commons/constants';
var FormValidatorsService = /** @class */ (function () {
    function FormValidatorsService() {
        this.CUSTOM_VALIDATED_TYPES = [
            'Date', 'MoneyGBP'
        ];
    }
    FormValidatorsService.prototype.addValidators = function (caseField, control) {
        if (caseField.display_context === Constants.MANDATORY
            && this.CUSTOM_VALIDATED_TYPES.indexOf(caseField.field_type.type) === -1) {
            var validators = [Validators.required];
            if (caseField.field_type.type === 'Text') {
                if (caseField.field_type.regular_expression) {
                    validators.push(Validators.pattern(caseField.field_type.regular_expression));
                }
                else {
                    validators.push(Validators.pattern(Constants.REGEX_WHITESPACES));
                }
                if (caseField.field_type.min) {
                    validators.push(Validators.minLength(caseField.field_type.min));
                }
                if (caseField.field_type.max) {
                    validators.push(Validators.maxLength(caseField.field_type.max));
                }
            }
            if (control.validator) {
                validators.push(control.validator);
            }
            control.setValidators(validators);
        }
        return control;
    };
    FormValidatorsService = __decorate([
        Injectable()
    ], FormValidatorsService);
    return FormValidatorsService;
}());
export { FormValidatorsService };
//# sourceMappingURL=form-validators.service.js.map