"use strict";

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

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

function _defineProperty2() {
  const data = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));

  _defineProperty2 = function () {
    return data;
  };

  return data;
}

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

  _chalk = function () {
    return data;
  };

  return data;
}

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

  _ramda = function () {
    return data;
  };

  return data;
}

function _command() {
  const data = _interopRequireDefault(require("../../command"));

  _command = function () {
    return data;
  };

  return data;
}

function _consumer() {
  const data = require("../../../api/consumer");

  _consumer = function () {
    return data;
  };

  return data;
}

function _generalError() {
  const data = _interopRequireDefault(require("../../../error/general-error"));

  _generalError = function () {
    return data;
  };

  return data;
}

function _constants() {
  const data = require("../../../constants");

  _constants = function () {
    return data;
  };

  return data;
}

class Untrack extends _command().default {
  constructor(...args) {
    super(...args);
    (0, _defineProperty2().default)(this, "name", 'untrack [ids...]');
    (0, _defineProperty2().default)(this, "description", `untrack a new component(s)
  https://${_constants().BASE_DOCS_DOMAIN}/docs/cli-untrack.html
  the id can be used with wildcards (e.g. bit untrack "utils/*")`);
    (0, _defineProperty2().default)(this, "alias", 'u');
    (0, _defineProperty2().default)(this, "opts", [['a', 'all', 'revert add for all tracked components']]);
    (0, _defineProperty2().default)(this, "loader", true);
    (0, _defineProperty2().default)(this, "migration", true);
  }

  action([components], {
    all
  }) {
    if (!_ramda().default.isEmpty(components) && all || _ramda().default.isEmpty(components) && !all) {
      throw new (_generalError().default)('you can use either a specific component [id] to untrack a particular component or --all flag to untrack them all');
    }

    return (0, _consumer().untrack)(components || [], all);
  }

  report({
    untrackedComponents,
    unRemovableComponents,
    missingComponents
  }) {
    const msg = [];

    if (_ramda().default.isEmpty(untrackedComponents) && _ramda().default.isEmpty(unRemovableComponents) && _ramda().default.isEmpty(missingComponents)) {
      return _chalk().default.underline.red('no components untracked');
    }

    if (!_ramda().default.isEmpty(untrackedComponents)) {
      const title = _chalk().default.underline('untracked components:\n');

      msg.push(title + untrackedComponents.map(result => _chalk().default.green(result)).join('\n'));
    }

    if (!_ramda().default.isEmpty(unRemovableComponents)) {
      msg.push(_chalk().default.red(`error: unable to untrack ${unRemovableComponents.join(', ')}, please use the bit remove command.\n`));
    }

    if (!_ramda().default.isEmpty(missingComponents)) {
      msg.push(_chalk().default.red(`fatal: component ${missingComponents.join(', ')} did not match any component.`));
    }

    return msg.join('\n');
  }

}

exports.default = Untrack;