"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 _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 Untag extends _command().default {
  constructor(...args) {
    super(...args);
    (0, _defineProperty2().default)(this, "name", 'untag [id] [version]');
    (0, _defineProperty2().default)(this, "description", `revert version(s) tagged for component(s)
  https://${_constants().BASE_DOCS_DOMAIN}/docs/cli-untag.html
  the id can be used with wildcards (e.g. bit untag "utils/*")`);
    (0, _defineProperty2().default)(this, "alias", '');
    (0, _defineProperty2().default)(this, "opts", [['a', 'all', 'revert tag for all tagged components'], ['f', 'force', 'revert tag although the tag is used as a dependency']]);
    (0, _defineProperty2().default)(this, "loader", true);
    (0, _defineProperty2().default)(this, "migration", true);
  }

  action([id, version], {
    all,
    force
  }) {
    if (!id && !all) {
      throw new (_generalError().default)('please specify a component ID or use --all flag');
    }

    if (all) {
      version = id;
      return (0, _consumer().unTagAction)(version, force);
    }

    return (0, _consumer().unTagAction)(version, force, id);
  }

  report(results) {
    const title = _chalk().default.green(`${results.length} component(s) were untagged:\n`);

    const components = results.map(result => {
      return `${_chalk().default.cyan(result.id.toStringWithoutVersion())}. version(s): ${result.versions.join(', ')}`;
    });
    return title + components.join('\n');
  }

}

exports.default = Untag;