"use strict";

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

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

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

  _ramda = function () {
    return data;
  };

  return data;
}

function _globalConfig() {
  const data = require("../../api/consumer/lib/global-config");

  _globalConfig = function () {
    return data;
  };

  return data;
}

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

  _constants = function () {
    return data;
  };

  return data;
}

const hubDomain = (0, _globalConfig().getSync)(_constants().CFG_HUB_DOMAIN_KEY) || _constants().DEFAULT_HUB_DOMAIN;

const hubResolver = scopeName => {
  const hubPrefix = `ssh://bit@${hubDomain}:`;
  return Promise.resolve(hubPrefix + scopeName);
};

const remoteResolver = (scopeName, thisScope) => {
  const resolverPath = _ramda().default.path(['scopeJson', 'resolverPath'], thisScope);

  let resolverFunction;

  if (!resolverPath) {
    resolverFunction = hubResolver;
  } else {
    // use the default resolver
    // $FlowFixMe
    resolverFunction = require(resolverPath);
  } // use the resolver described in the scopeJson


  return resolverFunction(scopeName, thisScope ? thisScope.name : undefined); // should return promise<string>
};

var _default = remoteResolver;
exports.default = _default;