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

  _scope = function () {
    return data;
  };

  return data;
}

function _bitId() {
  const data = require("../../../bit-id");

  _bitId = 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;
}

var _default =
/*#__PURE__*/
function () {
  var _catComponent = (0, _bluebird().coroutine)(function* (id) {
    const scope = yield (0, _scope().loadScope)();
    const bitId = yield scope.getParsedId(id); // $FlowFixMe unclear what's the issue here

    const component = yield scope.sources.get(bitId);
    if (!component) throw new (_generalError().default)('component was not found');

    if (bitId.hasVersion()) {
      const version = yield component.loadVersion(bitId.version, scope.objects);
      return version.toObject();
    }

    if (bitId.version === _constants().LATEST_BIT_VERSION && id.includes(_constants().VERSION_DELIMITER)) {
      const version = yield component.loadVersion(component.latest(), scope.objects);
      return version.toObject();
    }

    return component.toObject();
  });

  function catComponent(_x) {
    return _catComponent.apply(this, arguments);
  }

  return catComponent;
}();

exports.default = _default;