"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 _nothingToCompareTo() {
  const data = _interopRequireDefault(require("./exceptions/nothing-to-compare-to"));

  _nothingToCompareTo = function () {
    return data;
  };

  return data;
}

var _default =
/*#__PURE__*/
function () {
  var _getConsumerBit = (0, _bluebird().coroutine)(function* ({
    id,
    compare,
    allVersions,
    showRemoteVersions
  }) {
    const consumer = yield (0, _consumer().loadConsumer)();
    const bitId = consumer.getParsedId(id);

    if (allVersions) {
      return consumer.loadAllVersionsOfComponentFromModel(bitId);
    }

    const component = yield consumer.loadComponent(bitId); // loads recent component

    if (showRemoteVersions) {
      yield consumer.addRemoteAndLocalVersionsToDependencies(component, true);
    }

    if (compare) {
      if (!component.componentFromModel) throw new (_nothingToCompareTo().default)(id);
      return {
        component,
        componentModel: component.componentFromModel
      };
    }

    yield consumer.onDestroy();
    return {
      component
    };
  });

  function getConsumerBit(_x) {
    return _getConsumerBit.apply(this, arguments);
  }

  return getConsumerBit;
}();

exports.default = _default;