import { CommonModule } from '@angular/common';
import { Input, Directive, NgZone, ChangeDetectorRef, Optional, ContentChild, Component, ViewEncapsulation, ChangeDetectionStrategy, ContentChildren, Injectable, InjectionToken, Inject, Pipe, NgModule } from '@angular/core';
import { Subject, defer, of } from 'rxjs';
import { take, switchMap, takeUntil, filter } from 'rxjs/operators';
import { FormControl, NgForm, FormGroupDirective, Validators } from '@angular/forms';
import { trigger, transition } from '@angular/animations';
import { coerceNumberProperty, coerceBooleanProperty } from '@angular/cdk/coercion';
import { fadeOut, fadeIn } from '@ng-tangram/components/core';

var NtFormFieldControl = (function () {
    function NtFormFieldControl() {
    }
    NtFormFieldControl.prototype.focus = function () { };
    return NtFormFieldControl;
}());

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;
};
var NtFormLabelWidthDirective = (function () {
    function NtFormLabelWidthDirective() {
        this._widthChange = new Subject();
        this._width = 120;
    }
    Object.defineProperty(NtFormLabelWidthDirective.prototype, "width", {
        get: function () { return this._width; },
        set: function (value) {
            this._width = coerceNumberProperty(value, 120);
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(NtFormLabelWidthDirective.prototype, "widthChange", {
        get: function () { return this._widthChange.asObservable(); },
        enumerable: true,
        configurable: true
    });
    NtFormLabelWidthDirective.prototype.ngOnChanges = function (changes) {
        var change = changes.width;
        if (change.currentValue !== change.previousValue) {
            this._widthChange.next(change.currentValue);
        }
    };
    NtFormLabelWidthDirective.prototype.ngOnDestroy = function () {
        this._widthChange.complete();
    };
    __decorate([
        Input('ntFormLabelWidth')
    ], NtFormLabelWidthDirective.prototype, "width", null);
    NtFormLabelWidthDirective = __decorate([
        Directive({
            selector: 'form[ntFormLabelWidth]',
        })
    ], NtFormLabelWidthDirective);
    return NtFormLabelWidthDirective;
}());

var __decorate$1 = (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;
};
var NtFormOrientationDirective = (function () {
    function NtFormOrientationDirective() {
        this._orientationChange = new Subject();
    }
    Object.defineProperty(NtFormOrientationDirective.prototype, "orientation", {
        get: function () { return this._orientation; },
        set: function (value) {
            this._orientation = value;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(NtFormOrientationDirective.prototype, "orientationChange", {
        get: function () {
            return this._orientationChange.asObservable();
        },
        enumerable: true,
        configurable: true
    });
    NtFormOrientationDirective.prototype.ngOnChanges = function (changes) {
        var change = changes.orientation;
        if (change.currentValue !== change.previousValue) {
            this._orientationChange.next(change.currentValue);
        }
    };
    NtFormOrientationDirective.prototype.ngOnDestroy = function () {
        this._orientationChange.complete();
    };
    __decorate$1([
        Input('ntFormOrientation')
    ], NtFormOrientationDirective.prototype, "orientation", null);
    NtFormOrientationDirective = __decorate$1([
        Directive({
            selector: 'form[ntFormOrientation]',
        })
    ], NtFormOrientationDirective);
    return NtFormOrientationDirective;
}());

var __decorate$2 = (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;
};
var __param = (this && this.__param) || function (paramIndex, decorator) {
    return function (target, key) { decorator(target, key, paramIndex); }
};
var NtFormFieldComponent = (function () {
    function NtFormFieldComponent(_ngZone, _changeDetectorRef, parentForm, parentFormGroup, _formLabelWidth, _formOrientation) {
        var _this = this;
        this._ngZone = _ngZone;
        this._changeDetectorRef = _changeDetectorRef;
        this._formLabelWidth = _formLabelWidth;
        this._formOrientation = _formOrientation;
        this._destroy = new Subject();
        this._markVisible = true;
        this._isUnsetedWidthValue = true;
        this._ngForm = null;
        this._labelStyles = {};
        this._groupStyles = {};
        this._invalid = false;
        this._labelVisible = true;
        this._labelWidth = 120;
        this.statusChanges = defer(function () {
            if (_this.control && _this.ngControl) {
                return _this.ngControl.statusChanges ? _this.ngControl.statusChanges : of(null);
            }
            return _this._ngZone.onStable
                .asObservable()
                .pipe(take(1), switchMap(function () { return _this.statusChanges; }));
        });
        this._ngForm = parentForm || parentFormGroup;
        if (this._formLabelWidth) {
            this._subscribeContainerWidthChange();
        }
        if (this._formOrientation) {
            this._subscribeContainerOrientationChange();
        }
        this.statusChanges
            .pipe(takeUntil(this._destroy))
            .subscribe(function () { return _this._validate(); });
    }
    Object.defineProperty(NtFormFieldComponent.prototype, "labelVisible", {
        get: function () { return this._labelVisible; },
        set: function (value) {
            this._labelVisible = coerceBooleanProperty(value);
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(NtFormFieldComponent.prototype, "labelWidth", {
        get: function () { return this._labelWidth; },
        set: function (value) {
            var coercedValue = coerceNumberProperty(value, 0);
            if (coercedValue > 0) {
                this._isUnsetedWidthValue = false;
                this._labelWidth = coercedValue;
            }
            else {
                this._isUnsetedWidthValue = true;
                this._labelWidth = 120;
            }
            this._setHorizontalStyles();
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(NtFormFieldComponent.prototype, "orientation", {
        get: function () { return this._orientation; },
        set: function (value) {
            this._orientation = value;
            this._setHorizontalStyles();
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(NtFormFieldComponent.prototype, "markVisible", {
        get: function () { return this._markVisible; },
        set: function (value) {
            this._markVisible = coerceBooleanProperty(value);
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(NtFormFieldComponent.prototype, "required", {
        get: function () {
            if (this.ngControl &&
                this.ngControl.control &&
                this.ngControl.control.validator) {
                var control = new FormControl();
                var validateResult = this.ngControl.control.validator(control);
                return validateResult && validateResult.hasOwnProperty('required');
            }
            if (this.control) {
                return !!this.control.required;
            }
            return false;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(NtFormFieldComponent.prototype, "errors", {
        get: function () {
            return this.control.ngControl ? this.control.ngControl.errors : null;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(NtFormFieldComponent.prototype, "ngControl", {
        get: function () { return this.control ? this.control.ngControl : null; },
        enumerable: true,
        configurable: true
    });
    NtFormFieldComponent.prototype.ngAfterViewInit = function () {
        var _this = this;
        if (this._ngForm && this.ngControl) {
            this._ngForm.ngSubmit
                .pipe(takeUntil(this._destroy))
                .subscribe(function () { return _this._validate(); });
        }
    };
    NtFormFieldComponent.prototype.ngOnDestroy = function () {
        this._destroy.next();
        this._destroy.complete();
    };
    NtFormFieldComponent.prototype._clearValidateMessage = function () {
        this._invalid = false;
    };
    NtFormFieldComponent.prototype.isHorizontal = function () {
        return this.orientation === 'horizontal';
    };
    NtFormFieldComponent.prototype.isVertical = function () {
        return this.orientation === 'vertical';
    };
    NtFormFieldComponent.prototype._validate = function () {
        if (this.ngControl) {
            this._invalid = !!this.ngControl.invalid;
            this._changeDetectorRef.markForCheck();
        }
    };
    NtFormFieldComponent.prototype._subscribeContainerWidthChange = function () {
        var _this = this;
        this._formLabelWidth.widthChange.pipe(filter(function () { return _this._isUnsetedWidthValue; }), takeUntil(this._destroy))
            .subscribe(function (width) {
            _this._labelWidth = width;
            _this._setHorizontalStyles();
        });
    };
    NtFormFieldComponent.prototype._subscribeContainerOrientationChange = function () {
        var _this = this;
        this._formOrientation.orientationChange
            .pipe(filter(function () { return !_this._orientation; }), takeUntil(this._destroy))
            .subscribe(function (orientation) {
            _this._orientation = orientation;
            _this._setHorizontalStyles();
        });
    };
    NtFormFieldComponent.prototype._setHorizontalStyles = function () {
        if (this.labelWidth > 0 && this.isHorizontal()) {
            this._labelStyles['width.px'] = this.labelWidth;
            this._groupStyles['margin-left.px'] = this.labelWidth;
        }
        else {
            delete this._labelStyles['width.px'];
            delete this._groupStyles['margin-left.px'];
        }
    };
    NtFormFieldComponent.ctorParameters = function () { return [
        { type: NgZone },
        { type: ChangeDetectorRef },
        { type: NgForm, decorators: [{ type: Optional }] },
        { type: FormGroupDirective, decorators: [{ type: Optional }] },
        { type: NtFormLabelWidthDirective, decorators: [{ type: Optional }] },
        { type: NtFormOrientationDirective, decorators: [{ type: Optional }] }
    ]; };
    __decorate$2([
        Input()
    ], NtFormFieldComponent.prototype, "label", void 0);
    __decorate$2([
        Input()
    ], NtFormFieldComponent.prototype, "labelVisible", null);
    __decorate$2([
        Input()
    ], NtFormFieldComponent.prototype, "labelWidth", null);
    __decorate$2([
        Input()
    ], NtFormFieldComponent.prototype, "messages", void 0);
    __decorate$2([
        Input()
    ], NtFormFieldComponent.prototype, "orientation", null);
    __decorate$2([
        Input()
    ], NtFormFieldComponent.prototype, "markVisible", null);
    __decorate$2([
        ContentChild(NtFormFieldControl)
    ], NtFormFieldComponent.prototype, "control", void 0);
    NtFormFieldComponent = __decorate$2([
        Component({
            selector: 'nt-form-field',
            template: "\n    <label class=\"nt-form-label\"\n      *ngIf=\"labelVisible\"\n      [ngStyle]=\"_labelStyles\"\n      [class.required]=\"markVisible && required\">\n      {{label}}\n    </label>\n    <div class=\"nt-form-group\" [ngStyle]=\"_groupStyles\">\n      <ng-content></ng-content>\n      <span class=\"form-error is-visible\" *ngIf=\"_invalid && errors\" [@fade]=\"_invalid\">\n        {{ errors | formError:label:messages }}\n      </span>\n    </div>\n  ",
            animations: [
                trigger('fade', [
                    transition('* => false', fadeOut(.15)),
                    transition('* => true', fadeIn(.15))
                ])
            ],
            encapsulation: ViewEncapsulation.None,
            changeDetection: ChangeDetectionStrategy.OnPush,
            host: {
                'class': 'nt-form-field',
                '[class.nt-form-error]': '_invalid',
                '[class.nt-form-horizontal]': 'isHorizontal()'
            }
        }),
        __param(2, Optional()),
        __param(3, Optional()),
        __param(4, Optional()),
        __param(5, Optional())
    ], NtFormFieldComponent);
    return NtFormFieldComponent;
}());

var __decorate$3 = (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;
};
var __param$1 = (this && this.__param) || function (paramIndex, decorator) {
    return function (target, key) { decorator(target, key, paramIndex); }
};
var NtFormAutofocusDirective = (function () {
    function NtFormAutofocusDirective(form, formGroup) {
        this._destory = new Subject();
        this.formContainer = form || formGroup;
    }
    NtFormAutofocusDirective.prototype.ngAfterContentInit = function () {
        var _this = this;
        if (this.formContainer) {
            this.formContainer.ngSubmit
                .pipe(takeUntil(this._destory))
                .subscribe(function () {
                var field = _this.fields.find(function (field) { return !!field.ngControl && !!field.ngControl.invalid; });
                if (field && field.control) {
                    field.control.focus();
                }
            });
        }
    };
    NtFormAutofocusDirective.prototype.ngOnDestroy = function () {
        this._destory.next();
        this._destory.complete();
    };
    NtFormAutofocusDirective.ctorParameters = function () { return [
        { type: NgForm, decorators: [{ type: Optional }] },
        { type: FormGroupDirective, decorators: [{ type: Optional }] }
    ]; };
    __decorate$3([
        ContentChildren(NtFormFieldComponent, { descendants: true })
    ], NtFormAutofocusDirective.prototype, "fields", void 0);
    NtFormAutofocusDirective = __decorate$3([
        Directive({
            selector: 'form[ntFormAutofocus]'
        }),
        __param$1(0, Optional()),
        __param$1(1, Optional())
    ], NtFormAutofocusDirective);
    return NtFormAutofocusDirective;
}());

var __assign = (this && this.__assign) || function () {
    __assign = Object.assign || function(t) {
        for (var s, i = 1, n = arguments.length; i < n; i++) {
            s = arguments[i];
            for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
                t[p] = s[p];
        }
        return t;
    };
    return __assign.apply(this, arguments);
};
var __decorate$4 = (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;
};
var DEFAULT_TEMPLATES = {
    required: "请填写{0}",
    email: "{0}不是邮箱格式",
    min: "{0}必须输入大于{1}的数字",
    max: "{0}必须输入小于{1}的数字",
    pattern: "{0}不是合法的数据",
    maxlength: "{0}长度为最大{1}",
    minlength: "{0}长度为最小{1}",
    selection: '请选择{0}',
    upload: '请上传{0}',
    equalTo: '两次输入不一致',
    ltTo: '{0}的最小值应小于{1}',
    ltDateTo: '{0}应早于{1}',
    gtDateTo: '{0}应晚于{1}',
    unequalTo: '{0}必须和{1}不相同',
    intervalTo: '请输入正确区间值',
    notUnique: '{0}已存在',
    incorrect: '请输入正确{0}',
};
var NtFormValidationTransformer = (function () {
    function NtFormValidationTransformer() {
    }
    NtFormValidationTransformer.prototype.transform = function (errors, label, messages) {
        if (!errors) {
            return '';
        }
        var templates = __assign(__assign({}, DEFAULT_TEMPLATES), messages);
        if (errors.hasOwnProperty('required')) {
            if (errors.hasOwnProperty('selection')) {
                return this._format(templates['selection'], label);
            }
            else if (errors.hasOwnProperty('upload')) {
                return this._format(templates['upload'], label);
            }
            return this._format(templates['required'], label);
        }
        else if (errors.hasOwnProperty('email')) {
            return this._format(templates['email'], label);
        }
        else if (errors.hasOwnProperty('min')) {
            return this._format(templates['min'], label, errors.min.min);
        }
        else if (errors.hasOwnProperty('max')) {
            return this._format(templates['max'], label, errors.max.max);
        }
        else if (errors.hasOwnProperty('minlength')) {
            return this._format(templates['minlength'], label, errors.minlength.requiredLength);
        }
        else if (errors.hasOwnProperty('maxlength')) {
            return this._format(templates['maxlength'], label, errors.maxlength.requiredLength);
        }
        else if (errors.hasOwnProperty('pattern')) {
            return this._format(templates['pattern'], label);
        }
        else if (errors.hasOwnProperty('equalTo')) {
            return this._format(templates['equalTo'], label, errors.equalLabel);
        }
        else if (errors.hasOwnProperty('ltTo')) {
            return this._format(templates['ltTo'], label, errors.ltLabel);
        }
        else if (errors.hasOwnProperty('ltDateTo')) {
            return this._format(templates['ltDateTo'], label, errors.ltLabel);
        }
        else if (errors.hasOwnProperty('gtDateTo')) {
            return this._format(templates['gtDateTo'], label, errors.gtLabel);
        }
        else if (errors.hasOwnProperty('unequalTo')) {
            return this._format(templates['unequalTo'], label, errors.unequalLabel);
        }
        else if (errors.hasOwnProperty('intervalTo')) {
            return this._format(templates['intervalTo']);
        }
        else if (errors.hasOwnProperty('notUnique')) {
            return this._format(templates['notUnique'], label);
        }
        else if (errors.hasOwnProperty('incorrect')) {
            return this._format(templates['incorrect'], label);
        }
        else {
            return '';
        }
    };
    NtFormValidationTransformer.prototype._format = function (template) {
        var args = [];
        for (var _i = 1; _i < arguments.length; _i++) {
            args[_i - 1] = arguments[_i];
        }
        return template.replace(/\{(\d+)\}/g, function (match, number) {
            return typeof args[number] !== 'undefined' ? args[number] : match;
        });
    };
    NtFormValidationTransformer = __decorate$4([
        Injectable()
    ], NtFormValidationTransformer);
    return NtFormValidationTransformer;
}());
var NT_VALIDATION_TRANSFOMER = new InjectionToken('nt-validation-transformer');

var __decorate$5 = (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;
};
var __param$2 = (this && this.__param) || function (paramIndex, decorator) {
    return function (target, key) { decorator(target, key, paramIndex); }
};
var __read = (this && this.__read) || function (o, n) {
    var m = typeof Symbol === "function" && o[Symbol.iterator];
    if (!m) return o;
    var i = m.call(o), r, ar = [], e;
    try {
        while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
    }
    catch (error) { e = { error: error }; }
    finally {
        try {
            if (r && !r.done && (m = i["return"])) m.call(i);
        }
        finally { if (e) throw e.error; }
    }
    return ar;
};
var __spread = (this && this.__spread) || function () {
    for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i]));
    return ar;
};
var NtFormErrorPipe = (function () {
    function NtFormErrorPipe(_transformer) {
        this._transformer = _transformer;
    }
    NtFormErrorPipe.prototype.transform = function (value) {
        var _a;
        var args = [];
        for (var _i = 1; _i < arguments.length; _i++) {
            args[_i - 1] = arguments[_i];
        }
        return (_a = this._transformer).transform.apply(_a, __spread([value], args));
    };
    NtFormErrorPipe.ctorParameters = function () { return [
        { type: undefined, decorators: [{ type: Inject, args: [NT_VALIDATION_TRANSFOMER,] }] }
    ]; };
    NtFormErrorPipe = __decorate$5([
        Pipe({ name: 'formError' }),
        __param$2(0, Inject(NT_VALIDATION_TRANSFOMER))
    ], NtFormErrorPipe);
    return NtFormErrorPipe;
}());

var __decorate$6 = (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;
};
var NtFormsModule = (function () {
    function NtFormsModule() {
    }
    NtFormsModule_1 = NtFormsModule;
    NtFormsModule.forRoot = function (transformer) {
        return {
            ngModule: NtFormsModule_1,
            providers: [
                { provide: NT_VALIDATION_TRANSFOMER, useClass: transformer || NtFormValidationTransformer }
            ]
        };
    };
    var NtFormsModule_1;
    NtFormsModule = NtFormsModule_1 = __decorate$6([
        NgModule({
            imports: [CommonModule],
            exports: [
                NtFormFieldComponent,
                NtFormAutofocusDirective,
                NtFormLabelWidthDirective,
                NtFormOrientationDirective,
                NtFormErrorPipe
            ],
            declarations: [
                NtFormFieldComponent,
                NtFormAutofocusDirective,
                NtFormLabelWidthDirective,
                NtFormOrientationDirective,
                NtFormErrorPipe
            ]
        })
    ], NtFormsModule);
    return NtFormsModule;
}());

function requiredSelection(control) {
    var errors = Validators.required(control);
    return errors && errors.required ? { required: true, selection: true } : null;
}
function requiredUpload(control) {
    var errors = Validators.required(control);
    return errors && errors.required ? { required: true, upload: true } : null;
}
function equalTo(equalControl, equalLabel) {
    var subscribe;
    return function (control) {
        if (!subscribe) {
            subscribe = equalControl.valueChanges
                .pipe(filter(function () { return control.touched; }))
                .subscribe(function () {
                control.updateValueAndValidity();
            });
        }
        var controlValue = control.value;
        return equalControl.value == controlValue ? null : { equalTo: true, equalLabel: equalLabel };
    };
}
function unequalTo(equalControl, unequalLabel) {
    var subscribe;
    return function (control) {
        if (!subscribe) {
            subscribe = equalControl.valueChanges
                .pipe(filter(function () { return control.touched; }))
                .subscribe(function () {
                control.updateValueAndValidity();
            });
        }
        var controlValue = control.value;
        return equalControl.value !== controlValue ? null : { unequalTo: true, unequalLabel: unequalLabel };
    };
}
function interval(intervalLabel) {
    return function (control) {
        if (control.value) {
            var controlValue = control.value.split(/(\(|\)|\[|\]|,)/g);
            return Number(controlValue[2]) < Number(controlValue[4]) ? null : { intervalTo: true, intervalLabel: intervalLabel };
        }
        return null;
    };
}
function ltTo(withControl, ltLabel) {
    var subscribe;
    return function (control) {
        if (!subscribe) {
            subscribe = withControl.valueChanges
                .pipe(filter(function () { return control.touched; }))
                .subscribe(function () {
                control.updateValueAndValidity();
            });
        }
        var controlValue = control.value;
        if (withControl.value) {
            return Number(controlValue) < Number(withControl.value) ? null : { ltTo: true, ltLabel: ltLabel };
        }
        return null;
    };
}
function ltDateTo(withControl, ltLabel, dateAdapter) {
    var subscribe;
    return function (control) {
        if (!subscribe) {
            subscribe = withControl.valueChanges.subscribe(function () {
                control.updateValueAndValidity();
            });
        }
        if (withControl.value && control.value) {
            return dateAdapter.compareDate(dateAdapter.deserialize(control.value), dateAdapter.deserialize(withControl.value)) < 0 ? null : { ltDateTo: true, ltLabel: ltLabel };
        }
        return null;
    };
}
function gtDateTo(withControl, gtLabel, dateAdapter) {
    var subscribe;
    return function (control) {
        if (!subscribe) {
            subscribe = withControl.valueChanges.subscribe(function () {
                control.updateValueAndValidity();
            });
        }
        if (withControl.value && control.value) {
            return dateAdapter.compareDate(dateAdapter.deserialize(control.value), dateAdapter.deserialize(withControl.value)) > 0 ? null : { gtDateTo: true, gtLabel: gtLabel };
        }
        return null;
    };
}

export { DEFAULT_TEMPLATES, NT_VALIDATION_TRANSFOMER, NtFormAutofocusDirective, NtFormErrorPipe, NtFormFieldComponent, NtFormFieldControl, NtFormLabelWidthDirective, NtFormOrientationDirective, NtFormValidationTransformer, NtFormsModule, equalTo, gtDateTo, interval, ltDateTo, ltTo, requiredSelection, requiredUpload, unequalTo };
//# sourceMappingURL=forms.js.map
