"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 _componentsList() {
  const data = _interopRequireDefault(require("../../../consumer/component/components-list"));

  _componentsList = function () {
    return data;
  };

  return data;
}

function _component() {
  const data = _interopRequireDefault(require("../../../consumer/component"));

  _component = function () {
    return data;
  };

  return data;
}

function _models() {
  const data = require("../../../scope/models");

  _models = function () {
    return data;
  };

  return data;
}

function _analytics() {
  const data = require("../../../analytics/analytics");

  _analytics = function () {
    return data;
  };

  return data;
}

function _loader() {
  const data = _interopRequireDefault(require("../../../cli/loader"));

  _loader = function () {
    return data;
  };

  return data;
}

function _loaderMessages() {
  const data = require("../../../cli/loader/loader-messages");

  _loaderMessages = function () {
    return data;
  };

  return data;
}

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

  _bitId = function () {
    return data;
  };

  return data;
}

var _default =
/*#__PURE__*/
function () {
  var _status = (0, _bluebird().coroutine)(function* () {
    _loader().default.start(_loaderMessages().BEFORE_STATUS);

    const consumer = yield (0, _consumer().loadConsumer)();
    const componentsList = new (_componentsList().default)(consumer);
    const newAndImportPendingComponents = yield componentsList.listNewComponentsAndImportPending();
    const {
      newComponents,
      importPendingComponents
    } = newAndImportPendingComponents;
    const modifiedComponent = yield componentsList.listModifiedComponents(true);
    const stagedComponents = yield componentsList.listExportPendingComponents();
    const autoTagPendingComponents = yield componentsList.listAutoTagPendingComponents();
    const autoTagPendingComponentsStr = autoTagPendingComponents.map(component => component.id().toString());
    const invalidComponents = yield componentsList.listInvalidComponents();
    const outdatedComponents = yield componentsList.listOutdatedComponents(); // Run over the components to check if there is missing dependencies
    // If there is at least one we won't tag anything

    const newAndModified = newComponents.concat(modifiedComponent);
    const componentsWithMissingDeps = newAndModified.filter(component => {
      return Boolean(component.issues);
    });

    _analytics().Analytics.setExtraData('new_components', newComponents.length);

    _analytics().Analytics.setExtraData('staged_components', stagedComponents.length);

    _analytics().Analytics.setExtraData('num_components_with_missing_dependencies', componentsWithMissingDeps.length);

    _analytics().Analytics.setExtraData('autoTagPendingComponents', autoTagPendingComponents.length);

    _analytics().Analytics.setExtraData('deleted', invalidComponents.length);

    yield consumer.onDestroy();
    return {
      newComponents: _componentsList().default.sortComponentsByName(newComponents),
      modifiedComponent: _componentsList().default.sortComponentsByName(modifiedComponent),
      stagedComponents: _componentsList().default.sortComponentsByName(stagedComponents),
      componentsWithMissingDeps,
      // no need to sort, we don't print it as is
      importPendingComponents,
      // no need to sort, we use only its length
      autoTagPendingComponents: _componentsList().default.sortComponentsByName(autoTagPendingComponentsStr),
      invalidComponents,
      outdatedComponents
    };
  });

  function status() {
    return _status.apply(this, arguments);
  }

  return status;
}();

exports.default = _default;