'use strict';

var cli = require('../../_virtual/cli.js');
var colorize = require('./colorize.js');
var padLevels = require('./pad-levels.js');
require('../triple-beam/index.js');
var index = require('../../_virtual/index12.js');

var hasRequiredCli;

function requireCli () {
	if (hasRequiredCli) return cli.__module.exports;
	hasRequiredCli = 1;

	const { Colorizer } = colorize.__require();
	const { Padder } = padLevels.__require();
	const { configs, MESSAGE } = index.__exports;


	/**
	 * Cli format class that handles initial state for a a separate
	 * Colorizer and Padder instance.
	 */
	class CliFormat {
	  constructor(opts = {}) {
	    if (!opts.levels) {
	      opts.levels = configs.cli.levels;
	    }

	    this.colorizer = new Colorizer(opts);
	    this.padder = new Padder(opts);
	    this.options = opts;
	  }

	  /*
	   * function transform (info, opts)
	   * Attempts to both:
	   * 1. Pad the { level }
	   * 2. Colorize the { level, message }
	   * of the given `logform` info object depending on the `opts`.
	   */
	  transform(info, opts) {
	    this.colorizer.transform(
	      this.padder.transform(info, opts),
	      opts
	    );

	    info[MESSAGE] = `${info.level}:${info.message}`;
	    return info;
	  }
	}

	/*
	 * function cli (opts)
	 * Returns a new instance of the CLI format that turns a log
	 * `info` object into the same format previously available
	 * in `winston.cli()` in `winston < 3.0.0`.
	 */
	cli.__module.exports = opts => new CliFormat(opts);

	//
	// Attach the CliFormat for registration purposes
	//
	cli.__module.exports.Format = CliFormat;
	return cli.__module.exports;
}

exports.__require = requireCli;
