"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 core_1 = require("@angular/core");
var typescript_angular_utilities_1 = require("typescript-angular-utilities");
var __notification = typescript_angular_utilities_1.services.notification;
var __timeout = typescript_angular_utilities_1.services.timeout;
var busy_1 = require("../../busy/busy");
var buttonAsync_1 = require("../buttonAsync/buttonAsync");
var ButtonLongClickComponent = (function (_super) {
    __extends(ButtonLongClickComponent, _super);
    function ButtonLongClickComponent(notification, timeoutService) {
        var _this = _super.call(this) || this;
        // Should match the CSS animation time
        _this.duration = 2000;
        _this.notification = notification;
        _this.timeoutService = timeoutService;
        return _this;
    }
    ButtonLongClickComponent.prototype.startAction = function ($event) {
        var _this = this;
        if (this.active || this.busySpinner.loading) {
            return;
        }
        this.active = true;
        this.timer = this.timeoutService.setTimeout(function () {
            _this.cleanup();
            _this.triggerAction($event);
        }, this.duration).catch(function () { return _this.warn(); });
    };
    ButtonLongClickComponent.prototype.stopAction = function () {
        if (this.timer) {
            this.cleanup();
        }
    };
    ButtonLongClickComponent.prototype.cleanup = function () {
        this.timer.cancel();
        this.timer = null;
        this.active = false;
    };
    ButtonLongClickComponent.prototype.warn = function () {
        var warning = this.warning || 'Press and hold to complete this action';
        this.notification.warning(warning);
    };
    return ButtonLongClickComponent;
}(buttonAsync_1.ButtonAsyncComponent));
__decorate([
    core_1.Input(),
    __metadata("design:type", String)
], ButtonLongClickComponent.prototype, "warning", void 0);
__decorate([
    core_1.ViewChild(busy_1.BusyComponent),
    __metadata("design:type", busy_1.BusyComponent)
], ButtonLongClickComponent.prototype, "busySpinner", void 0);
ButtonLongClickComponent = __decorate([
    core_1.Component({
        selector: 'rlButtonLongClick',
        template: require('./buttonLongClick.html'),
        inputs: buttonAsync_1.asyncInputs,
    }),
    __metadata("design:paramtypes", [__notification.NotificationService, __timeout.TimeoutService])
], ButtonLongClickComponent);
exports.ButtonLongClickComponent = ButtonLongClickComponent;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYnV0dG9uTG9uZ0NsaWNrLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiYnV0dG9uTG9uZ0NsaWNrLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7Ozs7Ozs7Ozs7OztBQUFBLHNDQUE0RDtBQUU1RCw2RUFBd0Q7QUFDeEQsSUFBTyxjQUFjLEdBQUcsdUNBQVEsQ0FBQyxZQUFZLENBQUM7QUFDOUMsSUFBTyxTQUFTLEdBQUcsdUNBQVEsQ0FBQyxPQUFPLENBQUM7QUFFcEMsd0NBQWdEO0FBQ2hELDBEQUErRTtBQU8vRSxJQUFhLHdCQUF3QjtJQUFTLDRDQUFvQjtJQWFqRSxrQ0FBWSxZQUFnRCxFQUN4RCxjQUF3QztRQUQ1QyxZQUVDLGlCQUFPLFNBR1A7UUFiRCxzQ0FBc0M7UUFDdEMsY0FBUSxHQUFXLElBQUksQ0FBQztRQVV2QixLQUFJLENBQUMsWUFBWSxHQUFHLFlBQVksQ0FBQztRQUNqQyxLQUFJLENBQUMsY0FBYyxHQUFHLGNBQWMsQ0FBQzs7SUFDdEMsQ0FBQztJQUVELDhDQUFXLEdBQVgs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