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 __metadata = (this && this.__metadata) || function (k, v) {
    if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
var __param = (this && this.__param) || function (paramIndex, decorator) {
    return function (target, key) { decorator(target, key, paramIndex); }
};
import { Component, Inject } from '@angular/core';
import { Subject } from 'rxjs';
import { isNil } from 'lodash';
import { LOCALIZATION } from '../../localization';
let VerifyPasswordModalComponent = class VerifyPasswordModalComponent {
    constructor(localization) {
        this.localization = localization;
        this._onClosed = new Subject();
        this.passwordError = false;
    }
    get onClosed() {
        return this._onClosed;
    }
    ngOnInit() {
        this.validate();
    }
    validate() {
        if (isNil(this.password) || '' === this.password.trim()) {
            this.passwordError = true;
            this.validationErrorText = this.localization.passwordRequired;
        }
        else {
            this.passwordError = false;
            this.validationErrorText = '';
        }
    }
    checkSecurity() {
        this.securityChecker.isValid(this.password).then(isValid => {
            if (isValid) {
                this.close(true);
            }
            else {
                this.passwordError = true;
                this.validationErrorText = this.localization.passwordToolTip;
            }
        }).catch(() => {
            throw new Error('Failure of the checkSecurity');
        });
    }
    close(modalResult) {
        this._onClosed.next(modalResult);
        this._onClosed.complete();
    }
};
VerifyPasswordModalComponent = __decorate([
    Component({
        selector: 'verify-password',
        template: "<form #verifyPasswordForm=\"ngForm\" novalidate (ngSubmit)=\"checkSecurity()\" bs-modal-drag> <div class=\"modal-header\"> <h4 class=\"modal-title\"> <span>{{localization.passwordVerify}}</span> </h4> <button type=\"button\" class=\"close pull-right\" aria-label=\"Close\" (click)=\"close()\"> <span aria-hidden=\"true\">&times;</span> </button> </div> <div class=\"modal-body\"> <span class=\"password-span\">{{localization.password}}： </span> <input type=\"password\" name=\"password\" autoFocus class=\"form-control element-password\" [(ngModel)]=\"password\" (keyup)=\"validate()\" autocomplete=\"off\"> <span class=\"help-block text-danger\" [hidden]=\"!passwordError\">{{validationErrorText}}</span> </div> <div class=\"modal-footer\"> <button type=\"button\" class=\"btn md-skip btn-cancel\" (click)=\"close()\">{{localization.cancel}} </button> <button type=\"submit\" class=\"btn md-skip btn-primary\" [disabled]=\"passwordError\">{{localization.submit}}</button> </div> </form> ",
        styles: [".modal-header { padding: 10px; border-color: transparent; } .modal-body { position: relative; padding: 0px 5px !important; padding-top: 10px !important; } .modal-title { display: unset; margin-left: -6px; font-size: 16px !important; } .form-control { margin: 0 5%; float: none; width: 90%; } .modal-footer { padding: 10px 4px 20px 5px !important; text-align: right; border-color: transparent; color: #fff; } .text-danger { display: block; color: #ed6b75; font-size: 14px; margin: 5px 0px 0px 15px; } .btn-primary { color: #fff; height: 32px; margin-right: 10px; line-height: 0px } .password-span { color: #7f939e; font-size: 14px; margin-left: 15px; } .btn-cancel { color: #fff; height: 32px; min-width: 71px; margin-right: 6px; background-color: #dddddd; line-height: 0px } .element-password { padding-left: 8px; height: 32px; min-width: 71px; margin-left: 16px; } "]
    }),
    __param(0, Inject(LOCALIZATION)),
    __metadata("design:paramtypes", [Object])
], VerifyPasswordModalComponent);
export { VerifyPasswordModalComponent };
