"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 angular = require("angular");
var typescript_angular_utilities_1 = require("typescript-angular-utilities");
var promise_service_1 = require("../../../services/promise/promise.service");
var button_ng1_1 = require("../button/button.ng1");
var buttonAsync_ng1_1 = require("../buttonAsync/buttonAsync.ng1");
exports.moduleName = 'rl.ui.components.longClickButton';
exports.componentName = 'rlLongClickButton';
exports.controllerName = 'LongClickButtonController';
var LongClickButtonController = (function (_super) {
    __extends(LongClickButtonController, _super);
    function LongClickButtonController($scope, timeoutService, objectUtility, promise, notification) {
        var _this = _super.call(this, promise) || this;
        _this.$scope = $scope;
        _this.timeoutService = timeoutService;
        _this.objectUtility = objectUtility;
        _this.notification = notification;
        _this.duration = 2000; // Should match the CSS animation time
        return _this;
    }
    LongClickButtonController.prototype.startAction = function () {
        var _this = this;
        if (this.active || this.busy) {
            return;
        }
        this.active = true;
        this.timer = this.timeoutService.setTimeout(function () {
            _this.cleanup();
            _this.trigger();
            _this.$scope.$apply();
        }, this.duration).catch(function () { return null; });
    };
    LongClickButtonController.prototype.stopAction = function () {
        if (this.active) {
            if (this.timer != null) {
                this.warn();
            }
            this.cleanup();
        }
    };
    LongClickButtonController.prototype.cleanup = function () {
        this.timer.cancel();
        this.timer = null;
        this.active = false;
    };
    LongClickButtonController.prototype.warn = function () {
        var warning = this.warning || this.onShortClickText || 'Press and hold to complete this action';
        this.notification.warning(warning);
    };
    return LongClickButtonController;
}(buttonAsync_ng1_1.ButtonAsyncController));
LongClickButtonController.$inject = ['$scope', typescript_angular_utilities_1.downgrade.timeoutServiceName, typescript_angular_utilities_1.downgrade.objectServiceName, promise_service_1.serviceName, typescript_angular_utilities_1.downgrade.notificationServiceName];
exports.LongClickButtonController = LongClickButtonController;
var longClickButton = button_ng1_1.buildButton({
    template: require('./buttonLongClick.ng1.html'),
    controller: exports.controllerName,
    bindings: {
        warning: '@',
        busy: '<?',
        // deprecated
        onShortClickText: '@',
        icon: '@',
        text: '@',
    },
});
angular.module(exports.moduleName, [typescript_angular_utilities_1.downgrade.moduleName, promise_service_1.moduleName])
    .component(exports.componentName, longClickButton)
    .controller(exports.controllerName, LongClickButtonController);
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYnV0dG9uTG9uZ0NsaWNrLm5nMS5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbImJ1dHRvbkxvbmdDbGljay5uZzEudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7O0FBQUEsaUNBQW1DO0FBRW5DLDZFQUFtRTtBQUtuRSw2RUFBK0k7QUFHL0ksbURBQW1EO0FBQ25ELGtFQUF1RTtBQUU1RCxRQUFBLFVBQVUsR0FBVyxrQ0FBa0MsQ0FBQztBQUN4RCxRQUFBLGFBQWEsR0FBVyxtQkFBbUIsQ0FBQztBQUM1QyxRQUFBLGNBQWMsR0FBVywyQkFBMkIsQ0FBQztBQUVoRTtJQUErQyw2Q0FBcUI7SUFZbkUsbUNBQW9CLE1BQXNCLEVBQzlCLGNBQXdDLEVBQ3hDLGFBQXNDLEVBQzlDLE9BQXdCLEVBQ2hCLFlBQWlEO1FBSjdELFlBS0Msa0JBQU0sT0FBTyxDQUFDLFNBQ2Q7UUFObUIsWUFBTSxHQUFOLE1BQU0sQ0FBZ0I7UUFDOUIsb0JBQWMsR0FBZCxjQUFjLENBQTBCO1FBQ3hDLG1CQUFhLEdBQWIsYUFBYSxDQUF5QjtRQUV0QyxrQkFBWSxHQUFaLFlBQVksQ0FBcUM7UUFUN0QsY0FBUSxHQUFXLElBQUksQ0FBQyxDQUFDLHNDQUFzQzs7SUFXL0QsQ0FBQztJQUVELCtDQUFXLEdBQVg7UUFBQSxpQkFZQztRQVhBLEVBQUUsQ0FBQyxDQUFDLElBQUksQ0FBQyxNQ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