"use strict";
var __extends = (this && this.__extends) || function (d, b) {
    for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
    function __() { this.constructor = d; }
    d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
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); }
};
var core_1 = require("@angular/core");
var rxjs_1 = require("rxjs");
require("../../../../libraries/jSignature/jSignature.min");
var typescript_angular_utilities_1 = require("typescript-angular-utilities");
var __object = typescript_angular_utilities_1.services.object;
var __array = typescript_angular_utilities_1.services.array;
var __guid = typescript_angular_utilities_1.services.guid;
var validationInput_1 = require("../validationInput");
var componentValidator_service_1 = require("../../../services/componentValidator/componentValidator.service");
var form_1 = require("../../form/form");
var jquery_provider_1 = require("../../../services/jquery/jquery.provider");
var emptySignature_1 = require("./emptySignature");
var SignatureComponent = (function (_super) {
    __extends(SignatureComponent, _super);
    function SignatureComponent(rlForm, componentValidator, object, array, guid, jquery) {
        var _this = _super.call(this, rlForm, componentValidator, object, array, guid) || this;
        _this.inputType = 'signature';
        _this.jquery = jquery;
        return _this;
    }
    Object.defineProperty(SignatureComponent.prototype, "canvas", {
        get: function () {
            return this._canvas;
        },
        set: function (value) {
            if (value) {
                this._canvas = this.jquery(value.nativeElement);
            }
            else {
                this._canvas = null;
            }
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(SignatureComponent.prototype, "image", {
        get: function () {
            return this.value || this.getEmptyImage();
        },
        enumerable: true,
        configurable: true
    });
    SignatureComponent.prototype.ngAfterViewInit = function () {
        var _this = this;
        _super.prototype.ngAfterViewInit.call(this);
        setTimeout(function () { return _this.rendering = !_this.disabled; }, 0);
    };
    SignatureComponent.prototype.ngOnChanges = function (changes) {
        _super.prototype.ngOnChanges.call(this, changes);
        if (changes.disabled) {
            this.rendering = !changes.disabled.currentValue;
        }
        if (changes.value && this.canvas && changes.value.currentValue !== this.lastInternalChange) {
            this.canvas.jSignature('reset');
            if (changes.value.currentValue) {
                this.canvas.jSignature('setData', changes.value.currentValue);
            }
        }
    };
    SignatureComponent.prototype.ngAfterViewChecked = function () {
        var _this = this;
        if (this.rendering && this.canvas) {
            this.canvas.jSignature();
            if (this.value) {
                this.canvas.jSignature('setData', this.value);
            }
            rxjs_1.Observable.fromEvent(this.canvas, 'change').subscribe(function () { return _this.onChange(); });
            this.rendering = false;
        }
    };
    SignatureComponent.prototype.onChange = function () {
        var value = this.canvas.jSignature('getData', 'default');
        this.lastInternalChange = value;
        this.setValue(value);
    };
    SignatureComponent.prototype.reset = function () {
        this.canvas.jSignature('reset');
        this.setValue(null);
    };
    SignatureComponent.prototype.getEmptyImage = function () {
        return emptySignature_1.emptySignature;
    };
    SignatureComponent.prototype.setDisabled = function (disabled) {
        if (!disabled) {
            this.rendering = true;
        }
    };
    return SignatureComponent;
}(validationInput_1.ValidatedInputComponent));
__decorate([
    core_1.ViewChild('canvas'),
    __metadata("design:type", Object),
    __metadata("design:paramtypes", [Object])
], SignatureComponent.prototype, "canvas", null);
SignatureComponent = __decorate([
    core_1.Component({
        selector: 'rlSignature',
        template: require('./signature.html'),
        inputs: validationInput_1.validationInputs,
        outputs: validationInput_1.baseOutputs,
        providers: [componentValidator_service_1.ComponentValidator],
    }),
    __param(0, core_1.Optional()),
    __metadata("design:paramtypes", [form_1.FormComponent,
        componentValidator_service_1.ComponentValidator, __object.ObjectUtility, __array.ArrayUtility, __guid.GuidService, jquery_provider_1.JQueryProvider])
], SignatureComponent);
exports.SignatureComponent = SignatureComponent;
//# sourceMappingURL=data:application/json;base64, 