"use strict";

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

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.getScopeRemotes = getScopeRemotes;
exports.fetchRemoteVersions = fetchRemoteVersions;

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

  _bluebird = function () {
    return data;
  };

  return data;
}

function _ramda() {
  const data = _interopRequireDefault(require("ramda"));

  _ramda = function () {
    return data;
  };

  return data;
}

function _globalRemotes() {
  const data = _interopRequireDefault(require("../global-config/global-remotes"));

  _globalRemotes = function () {
    return data;
  };

  return data;
}

function _remotes() {
  const data = require("../remotes");

  _remotes = function () {
    return data;
  };

  return data;
}

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

  _bitId = function () {
    return data;
  };

  return data;
}

function getScopeRemotes(scope) {
  function mergeRemotes(globalRemotes) {
    const globalObj = globalRemotes.toPlainObject();
    return _remotes().Remotes.load(_ramda().default.merge(globalObj, scope.scopeJson.remotes));
  }

  return _globalRemotes().default.load().then(mergeRemotes);
}

function fetchRemoteVersions(_x, _x2) {
  return _fetchRemoteVersions.apply(this, arguments);
}

function _fetchRemoteVersions() {
  _fetchRemoteVersions = (0, _bluebird().coroutine)(function* (scope, componentIds) {
    const externals = componentIds.filter(id => !id.isLocal(scope.name));
    const remotes = yield getScopeRemotes(scope);
    return remotes.latestVersions(externals, scope);
  });
  return _fetchRemoteVersions.apply(this, arguments);
}