"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 _consumer() {
  const data = require("../../../consumer");

  _consumer = function () {
    return data;
  };

  return data;
}

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

  _generalError = function () {
    return data;
  };

  return data;
}

function _ejectComponents() {
  const data = _interopRequireDefault(require("../../../consumer/component-ops/eject-components"));

  _ejectComponents = function () {
    return data;
  };

  return data;
}

var _default =
/*#__PURE__*/
function () {
  var _eject = (0, _bluebird().coroutine)(function* (ids, force) {
    if (!ids || !ids.length) {
      throw new (_generalError().default)('please specify component ids to eject');
    }

    const consumer = yield (0, _consumer().loadConsumer)();
    const bitIds = ids.map(id => consumer.bitMap.getExistingBitId(id)); // this also assure that the ID is in .bitmap

    const ejectComponents = new (_ejectComponents().default)(consumer, bitIds, force);
    const ejectResults = yield ejectComponents.eject();
    yield consumer.onDestroy();
    return ejectResults;
  });

  function eject(_x, _x2) {
    return _eject.apply(this, arguments);
  }

  return eject;
}();

exports.default = _default;