"use strict";
var color = {
    // colors
    white: 37,
    black: 30,
    blue: 34,
    cyan: 36,
    green: 32,
    magenta: 35,
    red: 31,
    yellow: 33,
    bgWhite: 47,
    bgBlack: 40,
    bgBlue: 44,
    bgCyan: 46,
    bgGreen: 42,
    bgMagenta: 45,
    bgRed: 41,
    bgYellow: 43
};
var defineProps = Object.defineProperties;

function setColor() {};


function applyStyle() {
    // support varags, but simply cast to string in case there's only one arg
    var args = arguments;
    var argsLen = args.length;
    var str = argsLen !== 0 && String( arguments[ 0 ] );

    if ( argsLen > 1 ) {
        // don't slice `arguments`, it prevents v8 optimizations
        for ( var a = 1; a < argsLen; a++ ) {
            str += ' ' + args[ a ];
        }
    }

    var nestedStyles = this._styles;

    return '\x1b[' + color[ nestedStyles ] + 'm' + str + '\x1b[0m';

}

function build( _styles ) {
    var builder = function() {
        return applyStyle.apply( builder, arguments );
    };

    builder._styles = _styles;
    // __proto__ is used because we must return a function, but there is
    // no way to create a function with a different prototype.
    /* eslint-disable no-proto */
    //builder.__proto__ = proto;

    return builder;
}

function init() {
    var ret = {};

    Object.keys( color ).forEach( function( name ) {
        ret[ name ] = {
            get: function() {
                return build.call( this, [ name ] );
            }
        };
    } );

    return ret;
}

defineProps( setColor.prototype, init() );

module.exports = new setColor();