'use strict';

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.missingDependenciesLabels = undefined;
exports.default = missingDepsTemplate;

var _chalk;

function _load_chalk() {
  return _chalk = _interopRequireDefault(require('chalk'));
}

var _consumerComponent;

function _load_consumerComponent() {
  return _consumerComponent = _interopRequireDefault(require('../../consumer/component/consumer-component'));
}

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

var missingDependenciesLabels = exports.missingDependenciesLabels = {
  missingPackagesDependenciesOnFs: 'missing packages dependencies (use your package manager to make sure all package dependencies are installed)',
  missingComponents: 'missing components (use "bit import" or your package manager to make sure all components are installed)',
  untrackedDependencies: 'untracked file dependencies (use "bit add <file>" to track untracked files as components)',
  missingDependenciesOnFs: 'non-existing dependency files (please make sure all files exists on your workspace)',
  missingLinks: 'missing links (use "bit link" to build missing component links)',
  missingCustomModuleResolutionLinks: 'missing links (use "bit link" to build missing component links)',
  relativeComponents: 'components with relative import statements (please use absolute paths for imported components)'
};

function missingDepsTemplate(components) {
  function format(missingComponent) {
    return `${(_chalk || _load_chalk()).default.underline((_chalk || _load_chalk()).default.cyan(missingComponent.id.toString()))}\n${formatMissing(missingComponent)}`;
  }

  var result = `\n${components.map(format).join('\n')}`;
  return result;
}

function formatMissing(missingComponent) {
  function formatMissingStr(array, label) {
    if (!array || array.length === 0) return '';
    return (_chalk || _load_chalk()).default.yellow(`${label}: \n`) + (_chalk || _load_chalk()).default.white(Object.keys(array).map(function (key) {
      return `     ${key} -> ${array[key].join(', ')}`;
    }).join('\n'));
  }

  var missingStr = Object.keys(missingDependenciesLabels).map(function (key) {
    return formatMissingStr(missingComponent.missingDependencies[key], missingDependenciesLabels[key]);
  }).join('');

  return `${missingStr}\n`;
}