"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.getScopeComponent = getScopeComponent;
function _componentId() {
  const data = require("@teambit/component-id");
  _componentId = function () {
    return data;
  };
  return data;
}
function _loader() {
  const data = _interopRequireDefault(require("@teambit/legacy/dist/cli/loader"));
  _loader = function () {
    return data;
  };
  return data;
}
function _consumer() {
  const data = require("@teambit/legacy/dist/consumer");
  _consumer = function () {
    return data;
  };
  return data;
}
function _getRemoteByName() {
  const data = _interopRequireDefault(require("@teambit/legacy/dist/remotes/get-remote-by-name"));
  _getRemoteByName = function () {
    return data;
  };
  return data;
}
function _scope() {
  const data = require("@teambit/legacy/dist/scope");
  _scope = function () {
    return data;
  };
  return data;
}
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
async function getScopeComponent({
  id,
  allVersions,
  scopePath,
  showDependents,
  showDependencies,
  loadScopeFromCache
}) {
  const bitId = _componentId().ComponentID.fromString(id); // user used --remote so we know it has a scope

  if (scopePath) {
    // coming from the api
    const scope = await (0, _scope().loadScope)(scopePath, loadScopeFromCache);
    const component = await showComponentUsingScope(scope);
    return {
      component
    };
  }
  const consumer = await (0, _consumer().loadConsumerIfExist)();
  const remote = await (0, _getRemoteByName().default)(bitId.scope, consumer);
  _loader().default.start('showing a component...');
  const component = await remote.show(bitId);
  let dependenciesInfo = [];
  let dependentsInfo = [];
  if (showDependents || showDependencies) {
    // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
    const componentDepGraph = await remote.graph(component.id);
    if (showDependents) {
      // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
      dependentsInfo = componentDepGraph.getDependentsInfo(component.id);
    }
    if (showDependencies) {
      // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
      dependenciesInfo = componentDepGraph.getDependenciesInfo(component.id);
    }
  }
  // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
  return {
    component,
    dependentsInfo,
    dependenciesInfo
  };
  async function showComponentUsingScope(scope) {
    if (allVersions) {
      return scope.loadAllVersions(bitId);
    }
    const scopeComponentsImporter = scope.scopeImporter;
    return scopeComponentsImporter.loadRemoteComponent(bitId);
  }
}

//# sourceMappingURL=get-scope-component.js.map