'use strict';

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

var _ramda;

function _load_ramda() {
  return _ramda = _interopRequireDefault(require('ramda'));
}

var _chalk;

function _load_chalk() {
  return _chalk = _interopRequireDefault(require('chalk'));
}

var _bitId;

function _load_bitId() {
  return _bitId = require('../../bit-id');
}

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

exports.default = function (_ref, isRemote) {
  var dependentBits = _ref.dependentBits,
      _ref$modifiedComponen = _ref.modifiedComponents,
      modifiedComponents = _ref$modifiedComponen === undefined ? [] : _ref$modifiedComponen,
      removedComponentIds = _ref.removedComponentIds,
      missingComponents = _ref.missingComponents;

  var paintMissingComponents = function paintMissingComponents() {
    if ((_ramda || _load_ramda()).default.isEmpty(missingComponents)) return '';
    return (_chalk || _load_chalk()).default.red('missing components:') + (0, (_chalk || _load_chalk()).default)(` ${missingComponents.map(function (id) {
      if (!(id instanceof (_bitId || _load_bitId()).BitId)) id = new (_bitId || _load_bitId()).BitId(id); // when the id was received from a remote it's not an instance of BitId
      return id.version === 'latest' ? id.toStringWithoutVersion() : id.toString();
    })}\n`);
  };
  var paintRemoved = function paintRemoved() {
    if ((_ramda || _load_ramda()).default.isEmpty(removedComponentIds)) return '';
    var msg = isRemote ? 'successfully removed components from the remote scope:' : 'successfully removed components from the local scope (to remove from the remote scope, please re-run the command with --remote flag):';
    return (_chalk || _load_chalk()).default.green(msg) + (0, (_chalk || _load_chalk()).default)(` ${removedComponentIds.map(function (id) {
      return id.version === 'latest' ? id.toStringWithoutVersion() : id.toString();
    })}\n`);
  };

  var paintUnRemovedComponents = function paintUnRemovedComponents() {
    if ((_ramda || _load_ramda()).default.isEmpty(dependentBits)) return '';
    return Object.keys(dependentBits).map(function (key) {
      var header = (_chalk || _load_chalk()).default.underline.red(`error: unable to delete ${key}, because the following components depend on it:`);
      var body = dependentBits[key].join('\n');
      return `${header}\n${body}`;
    }).join('\n\n');
  };

  var paintModifiedComponents = function paintModifiedComponents() {
    return !(_ramda || _load_ramda()).default.isEmpty(modifiedComponents) ? `${(_chalk || _load_chalk()).default.red('error: unable to remove modified components (please use --force to remove modified components)\n') + (0, (_chalk || _load_chalk()).default)(`- ${modifiedComponents.map(function (id) {
      return id.version === 'latest' ? id.toStringWithoutVersion() : id.toString();
    })}`)}` : '';
  };

  return paintUnRemovedComponents(dependentBits) + paintRemoved(removedComponentIds) + paintMissingComponents(missingComponents) + paintModifiedComponents(modifiedComponents);
};