import { FormatMode } from '../../../i18n/i18n';
import { ModulVue } from '../../../vue/vue';
import { ControlValidatorValidationType } from '../../control-validator-validation-type';
import { FormControl } from '../../form-control';
import { ValidatorKeys } from '../validator-error-keys';
/**
 *
 * @param controlNames
 * @param controlLabels
 * @param options options required to personnalise the validator, like the timing of the validation or the error messages to display.
 */
export var CompareValidator = function (controlNames, controlLabels, options) {
    return {
        key: ValidatorKeys.Compare,
        validationFunction: function (control) {
            if (control instanceof FormControl) {
                throw Error('the compare controls validator should not be attached to a form control');
            }
            return controlNames
                .map(function (cn) { return control.getControl(cn); })
                .every(function (fc) {
                var source = (fc.value !== undefined ? fc.value : '');
                var target = (control.controls[0].value !== undefined ? control.controls[0].value : '');
                return source === target;
            });
        },
        error: options && options.error ?
            options.error : {
            message: options && controlLabels ?
                (ModulVue.prototype.$i18n).translate('m-form:compareValidatorErrorMessage', { controlNames: controlLabels.join(', ') }, undefined, undefined, undefined, FormatMode.Sprintf) :
                (ModulVue.prototype.$i18n).translate('m-form:compareValidatorErrorMessageNoName', undefined, undefined, undefined, undefined, FormatMode.Sprintf),
            groupMessage: options && controlLabels ?
                (ModulVue.prototype.$i18n).translate('m-form:compareValidatorErrorMessage', { controlNames: controlLabels.join(', ') }, undefined, undefined, undefined, FormatMode.Sprintf)
                : undefined
        },
        validationType: options && options.validationType ?
            options.validationType : ControlValidatorValidationType.Correction
    };
};
//# sourceMappingURL=compare.js.map