var __extends = (this && this.__extends) || (function () {
    var extendStatics = Object.setPrototypeOf ||
        ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
        function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
    return function (d, b) {
        extendStatics(d, b);
        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;
};
(function (factory) {
    if (typeof module === "object" && typeof module.exports === "object") {
        var v = factory(require, exports);
        if (v !== undefined) module.exports = v;
    }
    else if (typeof define === "function" && define.amd) {
        define(["require", "exports", "./Reporter"], factory);
    }
})(function (require, exports) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var Reporter_1 = require("./Reporter");
    /**
     * The Dom reporter outputs text into the DOM, essentially treating it like the console.
     */
    var Dom = (function (_super) {
        __extends(Dom, _super);
        function Dom(executor, options) {
            if (options === void 0) { options = {}; }
            var _this = _super.call(this, executor, options) || this;
            if (!_this.document) {
                _this.document = document;
            }
            if (!_this.suiteNode) {
                _this.suiteNode = _this.document.body;
            }
            return _this;
        }
        Dom.prototype.error = function (error) {
            var errorNode = this.document.createElement('pre');
            errorNode.appendChild(this.document.createTextNode(this.formatError(error)));
            this.document.body.appendChild(errorNode);
        };
        Dom.prototype.suiteEnd = function (suite) {
            this.suiteNode = (this.suiteNode.parentNode.parentNode || this.document.body);
            if (suite.error) {
                this.suiteNode.appendChild(this.document.createTextNode('Suite "' + suite.id + '" failed'));
                this.suiteNode.style.color = 'red';
                var errorNode = this.document.createElement('pre');
                errorNode.appendChild(this.document.createTextNode(this.formatError(suite.error)));
                this.suiteNode.appendChild(errorNode);
                this._scroll();
            }
        };
        Dom.prototype.suiteStart = function (suite) {
            var oldSuiteNode = this.suiteNode;
            this.suiteNode = this.document.createElement('ol');
            if (oldSuiteNode === this.document.body) {
                oldSuiteNode.appendChild(this.suiteNode);
            }
            else {
                var outerSuiteNode = this.document.createElement('li');
                var headerNode = this.document.createElement('div');
                headerNode.appendChild(this.document.createTextNode(suite.name));
                outerSuiteNode.appendChild(headerNode);
                outerSuiteNode.appendChild(this.suiteNode);
                oldSuiteNode.appendChild(outerSuiteNode);
            }
            this._scroll();
        };
        Dom.prototype.testEnd = function (test) {
            if (test.skipped) {
                var testNode = this.testNode = this.document.createElement('li');
                testNode.appendChild(this.document.createTextNode(test.name + ' skipped' +
                    (test.skipped ? ' (' + test.skipped + ')' : '')));
                testNode.style.color = 'gray';
                this.suiteNode.appendChild(testNode);
            }
            else if (test.error) {
                this.testNode.appendChild(this.document.createTextNode(' failed (' + test.timeElapsed + 'ms)'));
                this.testNode.style.color = 'red';
                var errorNode = this.document.createElement('pre');
                errorNode.appendChild(this.document.createTextNode(this.formatError(test.error)));
                this.testNode.appendChild(errorNode);
            }
            else {
                this.testNode.appendChild(this.document.createTextNode(' passed (' + test.timeElapsed + 'ms)'));
                this.testNode.style.color = 'green';
            }
            this._scroll();
        };
        Dom.prototype.testStart = function (test) {
            this.testNode = this.document.createElement('li');
            this.testNode.appendChild(this.document.createTextNode(test.name));
            this.suiteNode.appendChild(this.testNode);
            this._scroll();
        };
        Dom.prototype._scroll = function () {
            window.scrollTo(0, this.document.documentElement.scrollHeight || this.document.body.scrollHeight);
        };
        __decorate([
            Reporter_1.eventHandler()
        ], Dom.prototype, "error", null);
        __decorate([
            Reporter_1.eventHandler()
        ], Dom.prototype, "suiteEnd", null);
        __decorate([
            Reporter_1.eventHandler()
        ], Dom.prototype, "suiteStart", null);
        __decorate([
            Reporter_1.eventHandler()
        ], Dom.prototype, "testEnd", null);
        __decorate([
            Reporter_1.eventHandler()
        ], Dom.prototype, "testStart", null);
        return Dom;
    }(Reporter_1.default));
    exports.default = Dom;
});
//# sourceMappingURL=Dom.js.map