"use strict";

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

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

  _bluebird = function () {
    return data;
  };

  return data;
}

function _() {
  const data = require("..");

  _ = function () {
    return data;
  };

  return data;
}

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

  _constants = function () {
    return data;
  };

  return data;
}

function getTopLevelDependencies(_x, _x2) {
  return _getTopLevelDependencies.apply(this, arguments);
}

function _getTopLevelDependencies() {
  _getTopLevelDependencies = (0, _bluebird().coroutine)(function* (consumer, dependencyStatusProps) {
    const driver = consumer.driver.getDriver(false);
    const paths = dependencyStatusProps.mainFile;
    const consumerPath = consumer.getPath();
    const tree = yield driver.getDependencyTree({
      baseDir: consumerPath,
      consumerPath,
      filePaths: paths,
      bindingPrefix: _constants().DEFAULT_BINDINGS_PREFIX,
      resolveModulesConfig: consumer.config.resolveModules
    });
    const topLevelDependencies = Object.keys(tree.tree).map(topLevelFile => topLevelFile);
    return topLevelDependencies;
  });
  return _getTopLevelDependencies.apply(this, arguments);
}

function getComponentFiles(consumer) {
  const bitmap = consumer.bitMap;
  const componentsMaps = bitmap.getAllComponents();
  let componentFile = [];
  const values = Object.keys(componentsMaps).map(key => componentsMaps[key]);
  values.forEach(function (value) {
    if (value && value.files && Array.isArray(value.files)) {
      const currentFiles = [];
      value.files.forEach(function (file) {
        if (file && file.relativePath) currentFiles.push(file.relativePath);
      });
      componentFile = componentFile.concat(currentFiles);
    }
  });
  return componentFile;
}

var _default =
/*#__PURE__*/
function () {
  var _getDependencyStatus = (0, _bluebird().coroutine)(function* (consumer, dependencyStatusProps) {
    const topLevelDependencies = yield getTopLevelDependencies(consumer, dependencyStatusProps);
    const componentFiles = getComponentFiles(consumer);
    const missingDependencyFiles = [];
    topLevelDependencies.forEach(function (dependency) {
      if (!componentFiles.includes(dependency)) {
        missingDependencyFiles.push(dependency);
      }
    });
    const results = {
      missingFiles: missingDependencyFiles
    };
    return results;
  });

  function getDependencyStatus(_x3, _x4) {
    return _getDependencyStatus.apply(this, arguments);
  }

  return getDependencyStatus;
}();

exports.default = _default;