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, Output } from '@angular/core';
import { Subject } from 'rxjs';
import { LOCALIZATION } from '../../localization';
let WriteCharacterModalComponent = class WriteCharacterModalComponent {
    constructor(localization) {
        this.localization = localization;
        this._onClosed = new Subject();
    }
    get onClosed() {
        return this._onClosed;
    }
    get invalidErrorText() {
        return this.localization.loadFailed;
    }
    ngOnInit() {
        this.variableName = this.args.variableName;
        this.isPassword = this.args.isPassword ? this.args.isPassword : false;
        this.charCount = this.args.charCount;
        this.value = '';
        this.validate();
    }
    validate() {
        // 校验数值必填
        if (null == this.value || '' === this.value.trim()) {
            return this.showValidationErrorInfo(this.localization.characterInputRequired);
        }
        if (this.value.length > this.charCount) {
            return this.showValidationErrorInfo(this.localization.characterOutofRange);
        }
        this.hideValidationErrorInfo();
    }
    showValidationErrorInfo(errorText) {
        this.validationError = true;
        this.validationErrorText = errorText;
    }
    hideValidationErrorInfo() {
        this.validationError = false;
        this.validationErrorText = '';
    }
    save() {
        this.close({ value: this.value });
    }
    close(modalResult) {
        this._onClosed.next(modalResult);
        this._onClosed.complete();
    }
};
__decorate([
    Output(),
    __metadata("design:type", String),
    __metadata("design:paramtypes", [])
], WriteCharacterModalComponent.prototype, "invalidErrorText", null);
WriteCharacterModalComponent = __decorate([
    Component({
        selector: 'writeCharacterModal',
        template: "<form #writeValueForm=\"ngForm\" novalidate (ngSubmit)=\"save()\" bs-modal-drag> <div class=\"modal-header\"> <h4 class=\"modal-title\"> <span>{{localization.setting}}</span> <span>{{variableName}}</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\"> <input type=\"text\" name=\"characterInput\" autoFocus class=\"form-control write-character-value\" [(ngModel)]=\"value\" (keyup)=\"validate()\" *ngIf=\"!isPassword\" autocomplete=\"off\"> <input type=\"password\" name=\"passwordInput\" autoFocus class=\"form-control write-character-value\" [(ngModel)]=\"value\" (keyup)=\"validate()\" *ngIf=\"isPassword\" autocomplete=\"off\"> <span class=\"help-block text-danger\" [hidden]=\"!validationError\">{{validationErrorText}}</span> </div> <div class=\"modal-footer\"> <button type=\"submit\" class=\"btn md-skip btn-primary btn-block\" [disabled]=\"validationError\">{{localization.submit}}</button> </div> </form> ",
        styles: [".modal-header { padding: 10px; border-color: transparent; } .modal-body { position: relative; padding: 0px 5px !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; } .text-danger { display: block; color: #ed6b75; font-size: 14px; margin: 10px 0px 0px 15px; } .btn-primary { background-color: #3B97FC; border-color: #3B97FC; padding: 5px 30px; width: 90%; margin: 0 5%; height: 32px; } .write-character-value { padding-left: 8px; height: 32px; margin-left: 16px; } "]
    }),
    __param(0, Inject(LOCALIZATION)),
    __metadata("design:paramtypes", [Object])
], WriteCharacterModalComponent);
export { WriteCharacterModalComponent };
