"use strict";
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;
};
exports.__esModule = true;
exports.AuthComponent = void 0;
var core_1 = require("@angular/core");
var forms_1 = require("@angular/forms");
var AuthComponent = /** @class */ (function () {
    function AuthComponent(authService, rounter, notificationService) {
        this.authService = authService;
        this.rounter = rounter;
        this.notificationService = notificationService;
        this.userForm = new forms_1.FormGroup({
            password: new forms_1.FormControl('password', [forms_1.Validators.minLength(3), forms_1.Validators.maxLength(20)]),
            email: new forms_1.FormControl('email@email.com', forms_1.Validators.email)
        });
    }
    AuthComponent.prototype.ngOnInit = function () {
        var _this = this;
        this.loginSub = this.authService.loginSuccess.subscribe(function (ok) { _this.onLogin(ok); });
    };
    AuthComponent.prototype.ngOnDestroy = function () {
        this.loginSub.unsubscribe();
    };
    AuthComponent.prototype.submitForm = function () {
        console.log(this.userForm);
        this.loading = true;
        this.authService.login(this.userForm.value.email, this.userForm.value.password);
    };
    AuthComponent.prototype.onLogin = function (ok) {
        this.loading = false;
        console.log(" found login success " + ok);
        if (ok)
            this.rounter.navigate(["/dashboard"]);
        else
            this.show();
    };
    AuthComponent.prototype.show = function () {
        this.notificationService.show({
            content: 'Your loggin is failed, please try again.',
            cssClass: 'button-notification',
            animation: { type: 'slide', duration: 400 },
            position: { horizontal: 'center', vertical: 'top' },
            type: { style: 'error', icon: true },
            hideAfter: 2000
        });
    };
    AuthComponent = __decorate([
        core_1.Component({
            selector: 'app-auth',
            templateUrl: './auth.component.html',
            styleUrls: ['./auth.component.scss']
        })
    ], AuthComponent);
    return AuthComponent;
}());
exports.AuthComponent = AuthComponent;
