"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var lang_1 = require("@dojo/core/lang");
var Reporter = (function () {
    function Reporter(executor, config) {
        if (config === void 0) { config = {}; }
        lang_1.mixin(this, config);
        this.executor = executor;
        this._registerEventHandlers();
    }
    Object.defineProperty(Reporter.prototype, "console", {
        get: function () {
            if (!this._console) {
                this._console = getConsole();
            }
            return this._console;
        },
        set: function (value) {
            this._console = value;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(Reporter.prototype, "formatter", {
        get: function () {
            return this.executor.formatter;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(Reporter.prototype, "output", {
        get: function () {
            if (!this._output) {
                if (typeof process !== 'undefined') {
                    return process.stdout;
                }
                else {
                    var _console_1 = this.console;
                    this._output = {
                        write: function (chunk, _encoding, callback) {
                            _console_1.log(chunk);
                            callback();
                        },
                        end: function (chunk, _encoding, callback) {
                            _console_1.log(chunk);
                            callback();
                        }
                    };
                }
            }
            return this._output;
        },
        set: function (value) {
            this._output = value;
        },
        enumerable: true,
        configurable: true
    });
    Reporter.prototype._registerEventHandlers = function () {
        var _this = this;
        if (!this._eventHandlers) {
            return;
        }
        Object.keys(this._eventHandlers).forEach(function (name) {
            _this.executor.on(name, function () {
                var args = [];
                for (var _i = 0; _i < arguments.length; _i++) {
                    args[_i] = arguments[_i];
                }
                var handler = _this._eventHandlers[name];
                return (_a = _this)[handler].apply(_a, args);
                var _a;
            });
        });
    };
    return Reporter;
}());
exports.default = Reporter;
function createEventHandler() {
    return function (name) {
        return function (target, propertyKey, _descriptor) {
            if (!target.hasOwnProperty('_eventHandlers')) {
                target._eventHandlers = {};
            }
            target._eventHandlers[name || propertyKey] = propertyKey;
        };
    };
}
exports.createEventHandler = createEventHandler;
exports.eventHandler = createEventHandler();
function getConsole() {
    if (typeof console !== 'undefined') {
        return console;
    }
    return {
        assert: noop,
        count: noop,
        dir: noop,
        error: noop,
        exception: noop,
        info: noop,
        log: noop,
        table: noop,
        time: noop,
        timeEnd: noop,
        trace: noop,
        warn: noop
    };
}
function noop() {
}
//# sourceMappingURL=Reporter.js.map