"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;

function _ramda() {
  const data = _interopRequireDefault(require("ramda"));

  _ramda = function () {
    return data;
  };

  return data;
}

function _chalk() {
  const data = _interopRequireDefault(require("chalk"));

  _chalk = function () {
    return data;
  };

  return data;
}

function _bitId() {
  const data = require("../../bit-id");

  _bitId = function () {
    return data;
  };

  return data;
}

var _default = ({
  dependentBits,
  modifiedComponents = [],
  removedComponentIds,
  missingComponents
}, isRemote) => {
  const paintMissingComponents = () => {
    if (_ramda().default.isEmpty(missingComponents)) return '';
    return _chalk().default.red('missing components (try to `bit untrack` them instead):') + (0, _chalk().default)(` ${missingComponents.map(id => {
      if (!(id instanceof _bitId().BitId)) id = new (_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`);
  };

  const paintRemoved = () => {
    if (_ramda().default.isEmpty(removedComponentIds)) return '';
    const 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().default.green(msg) + (0, _chalk().default)(` ${removedComponentIds.map(id => id.version === 'latest' ? id.toStringWithoutVersion() : id.toString())}\n`);
  };

  const paintUnRemovedComponents = () => {
    if (_ramda().default.isEmpty(dependentBits)) return '';
    return Object.keys(dependentBits).map(key => {
      const header = _chalk().default.underline.red(`error: unable to delete ${key}, because the following components depend on it:`);

      const body = dependentBits[key].join('\n');
      return `${header}\n${body}`;
    }).join('\n\n');
  };

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

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

exports.default = _default;