'use strict';

Object.defineProperty(exports, '__esModule', {
    value: true
});
var NEW_LINE = '\n ';

exports['default'] = function () {
    return {
        noColors: false,
        spaceLeft: 0,
        errDescriptors: [],
        currentFixtureName: null,
        testCount: 0,
        skipped: 0,

        reportTaskStart: function reportTaskStart(startTime, userAgents, testCount) {
            var _this = this;

            this.testCount = testCount;

            this.setIndent(1).useWordWrap(true).write(this.chalk.bold('Running tests in:')).newline();

            userAgents.forEach(function (ua) {
                _this.write('- ' + _this.chalk.blue(ua)).newline();
            });
        },

        reportFixtureStart: function reportFixtureStart(name) {
            this.currentFixtureName = name;
        },

        reportTestDone: function reportTestDone(name, testRunInfo) {
            var _this2 = this;

            var hasErr = !!testRunInfo.errs.length;
            var symbol = null;

            if (testRunInfo.skipped) {
                this.skipped++;

                symbol = this.chalk.cyan('-');
            } else if (hasErr) symbol = this.chalk.red('!');else symbol = '.';

            if (this.spaceLeft - 1 < 0) {
                this.spaceLeft = this.viewportWidth - NEW_LINE.length - 1;
                this.write(NEW_LINE);
            } else this.spaceLeft--;

            this.write(symbol);

            if (hasErr) {
                this.errDescriptors = this.errDescriptors.concat(testRunInfo.errs.map(function (err) {
                    return {
                        err: err,
                        testName: name,
                        fixtureName: _this2.currentFixtureName
                    };
                }));
            }
        },

        _renderErrors: function _renderErrors() {
            var _this3 = this;

            this.newline();

            this.errDescriptors.forEach(function (errDescriptor) {
                var title = _this3.chalk.bold.red(_this3.symbols.err) + ' ' + errDescriptor.fixtureName + ' - ' + errDescriptor.testName;

                _this3.setIndent(1).useWordWrap(true).newline().write(title).newline().newline().setIndent(3).write(_this3.formatError(errDescriptor.err)).newline().newline();
            });
        },

        _renderWarnings: function _renderWarnings(warnings) {
            var _this4 = this;

            this.newline().setIndent(1).write(this.chalk.bold.yellow('Warnings (' + warnings.length + '):')).newline();

            warnings.forEach(function (msg) {
                _this4.setIndent(1).write(_this4.chalk.bold.yellow('--')).newline().setIndent(2).write(msg).newline();
            });
        },

        reportTaskDone: function reportTaskDone(endTime, passed, warnings) {
            var allPassed = !this.errDescriptors.length;
            var footer = allPassed ? this.chalk.bold.green(this.testCount + ' passed') : this.chalk.bold.red(this.testCount - passed + '/' + this.testCount + ' failed');

            if (!allPassed) this._renderErrors();else this.newline();

            this.setIndent(1).newline().write(footer).newline();

            if (this.skipped > 0) {
                this.write(this.chalk.cyan(this.skipped + ' skipped')).newline();
            }

            if (warnings.length) this._renderWarnings(warnings);
        }
    };
};

module.exports = exports['default'];