'use strict';

Object.defineProperty(exports, "__esModule", {
  value: true
});

var _lodash = require('lodash');

var _lodash2 = _interopRequireDefault(_lodash);

var _chalk = require('chalk');

var _chalk2 = _interopRequireDefault(_chalk);

var _util = require('util');

var _util2 = _interopRequireDefault(_util);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

const MAP = {
  0: _chalk2.default.blue.dim, // default value
  1: _chalk2.default.blue.dim,
  2: _chalk2.default.green.dim,
  3: _chalk2.default.yellow.dim,
  4: _chalk2.default.magenta.dim,
  5: _chalk2.default.red.dim
};

function getFormatMethod(code) {
  const firstDigitOfCode = code.toString()[0];

  return MAP[firstDigitOfCode] || MAP[0];
}

function printCode(code, str) {
  return getFormatMethod(code)(str || code);
}

function printSourceCode(contentType, source) {
  if (contentType === 'application/json') {
    const object = JSON.parse(source);
    return _util2.default.inspect(object, { depth: null, colors: true });
  }
  return source.toString();
}

function echo(...args) {
  if (Number.isInteger(args[0])) {
    const padding = args[0];
    return (...nextArgs) => {
      process.stdout.write(`${_util2.default.format(_lodash2.default.repeat(' ', padding) + nextArgs.join(' '))} \n`);
    };
  }
  process.stdout.write(`${_util2.default.format(args.join(' '))} \n`);
}

function echon(...args) {
  if (Number.isInteger(args[0])) {
    const padding = args[0];
    return (...nextArgs) => {
      process.stdout.write(`${_util2.default.format(_lodash2.default.repeat(' ', padding) + nextArgs.join(' '))}`);
    };
  }
  process.stdout.write(`${_util2.default.format(args.join(' '))}`);
}

function error(...args) {
  if (args.length === 1 && !Number.isInteger(args[0])) {
    // args.unshift('ERROR:');
    process.stdout.write(_util2.default.format(_chalk2.default.red(args.join(' '), '\n')));
    return;
  }

  if (Number.isInteger(args[0])) {
    const padding = args[0];
    return (...nextArgs) => {
      // nextArgs.unshift('ERROR:');
      process.stdout.write(_util2.default.format(_lodash2.default.repeat(' ', padding) + _chalk2.default.red(nextArgs.join(' '), '\n')));
    };
  }

  process.stdout.write(_util2.default.format(_chalk2.default.red(args.join('\n\n'), '\n')));
}

function warning(...args) {
  // args.unshift('WARNING:');
  process.stdout.write(_util2.default.format(_chalk2.default.yellow(args.join(' '), '\n')));
}

const p = padding => string => {
  let str = '';
  if (string) {
    str = string.split('\n').join(`\n${_lodash2.default.repeat(' ', padding)}`);
  }
  return _lodash2.default.repeat(' ', padding) + str;
};

exports.default = {
  MAP,
  getFormatMethod,
  printCode,
  printSourceCode,
  echo,
  echon,
  error,
  warning,
  p
};
module.exports = exports['default'];
//# sourceMappingURL=print-tools.js.map