"use strict";

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

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

function _bluebird() {
  const data = require("bluebird");

  _bluebird = function () {
    return data;
  };

  return data;
}

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

  _defineProperty2 = function () {
    return data;
  };

  return data;
}

function _yn() {
  const data = _interopRequireDefault(require("yn"));

  _yn = 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 _removedComponents() {
  const data = require("../../../scope/removed-components");

  _removedComponents = function () {
    return data;
  };

  return data;
}

function _removeTemplate() {
  const data = _interopRequireDefault(require("../../templates/remove-template"));

  _removeTemplate = function () {
    return data;
  };

  return data;
}

function _prompts() {
  const data = require("../../../prompts");

  _prompts = function () {
    return data;
  };

  return data;
}

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

  _constants = function () {
    return data;
  };

  return data;
}

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

  _generalError = function () {
    return data;
  };

  return data;
}

class Remove extends _command().default {
  constructor(...args) {
    super(...args);
    (0, _defineProperty2().default)(this, "name", 'remove <ids...>');
    (0, _defineProperty2().default)(this, "description", `remove a component (local/remote)
  https://${_constants().BASE_DOCS_DOMAIN}/docs/removing-components.html
  the id can be used with wildcards (e.g. bit remove "utils/*")`);
    (0, _defineProperty2().default)(this, "alias", 'rm');
    (0, _defineProperty2().default)(this, "opts", [['f', 'force [boolean]', 'force remove (default = false)'], ['r', 'remote', 'remove a component from a remote scope'], ['t', 'track [boolean]', 'keep tracking component (default = false)'], ['d', 'delete-files [boolean]', 'delete local component files (authored components only. for imported components the files are always deleted)'], ['s', 'silent [boolean]', 'skip confirmation']]);
    (0, _defineProperty2().default)(this, "loader", true);
    (0, _defineProperty2().default)(this, "migration", true);
  }

  action([ids], {
    force = false,
    remote = false,
    track = false,
    deleteFiles = false,
    silent = false
  }) {
    return (0, _bluebird().coroutine)(function* () {
      if (!silent) {
        const removePromptResult = yield (0, _prompts().removePrompt)();

        if (!(0, _yn().default)(removePromptResult.shouldRemove)) {
          throw new (_generalError().default)('the operation has been canceled');
        }
      }

      return (0, _consumer().remove)({
        ids,
        remote,
        force,
        track,
        deleteFiles
      });
    })();
  }

  report({
    localResult,
    remoteResult = []
  }) {
    return (0, _removeTemplate().default)(localResult, false) + this.paintArray(remoteResult);
  }

  paintArray(removedObjectsArray) {
    // $FlowFixMe
    return removedObjectsArray.map(item => (0, _removeTemplate().default)(item, true));
  }

}

exports.default = Remove;