"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 promise_service_1 = require("../../../services/promise/promise.service");
var button_ng1_1 = require("../button/button.ng1");
exports.moduleName = 'rl.ui.components.buttonAsync';
exports.componentName = 'rlButtonAsync';
exports.controllerName = 'ButtonAsyncController';
var ButtonAsyncController = (function (_super) {
    __extends(ButtonAsyncController, _super);
    function ButtonAsyncController(promiseUtility) {
        var _this = _super.call(this) || this;
        _this.promiseUtility = promiseUtility;
        return _this;
    }
    ButtonAsyncController.prototype.trigger = function () {
        var _this = this;
        if (!this.busy) {
            this.busy = true;
            var result = this.action();
            if (this.promiseUtility.isPromise(result)) {
                return result.then(function () {
                    _this.busy = false;
                }).catch(function (error) {
                    _this.busy = false;
                    throw error;
                });
            }
            else if (result !== true) {
                this.busy = false;
            }
        }
        return null;
    };
    return ButtonAsyncController;
}(button_ng1_1.ButtonController));
ButtonAsyncController.$inject = [promise_service_1.serviceName];
exports.ButtonAsyncController = ButtonAsyncController;
var buttonAsync = button_ng1_1.buildButton({
    template: require('./buttonAsync.ng1.html'),
    bindings: {
        busy: '<?',
    },
    controller: exports.controllerName,
});
angular.module(exports.moduleName, [promise_service_1.moduleName])
    .component(exports.componentName, buttonAsync)
    .controller(exports.controllerName, ButtonAsyncController);
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYnV0dG9uQXN5bmMubmcxLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiYnV0dG9uQXN5bmMubmcxLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7OztBQUFBLGlDQUFtQztBQUduQyw2RUFBK0k7QUFFL0ksbURBQXFFO0FBRXhELFFBQUEsVUFBVSxHQUFXLDhCQUE4QixDQUFDO0FBRXBELFFBQUEsYUF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