"use strict";

var _regeneratorRuntime = require("babel-runtime/regenerator")["default"];

var _getIterator = require("babel-runtime/core-js/get-iterator")["default"];

exports.__esModule = true;

exports["default"] = function callee$0$0(packages) {
  var foundDeps, foundDuplicated, duplicatedPackages, checkDep, _iterator, _isArray, _i, _ref, pkg, msg, _name;

  return _regeneratorRuntime.async(function callee$0$0$(context$1$0) {
    while (1) switch (context$1$0.prev = context$1$0.next) {
      case 0:
        checkDep = function checkDep(name) {
          if (name.indexOf("babel-") === 0 && foundDeps[name]) {
            foundDuplicated = true;
            duplicatedPackages[name] = (duplicatedPackages[name] || 0) + 1;
          }

          foundDeps[name] = true;
        };

        foundDeps = {};
        foundDuplicated = false;
        duplicatedPackages = {};
        _iterator = packages, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _getIterator(_iterator);

      case 5:
        if (!_isArray) {
          context$1$0.next = 11;
          break;
        }

        if (!(_i >= _iterator.length)) {
          context$1$0.next = 8;
          break;
        }

        return context$1$0.abrupt("break", 19);

      case 8:
        _ref = _iterator[_i++];
        context$1$0.next = 15;
        break;

      case 11:
        _i = _iterator.next();

        if (!_i.done) {
          context$1$0.next = 14;
          break;
        }

        return context$1$0.abrupt("break", 19);

      case 14:
        _ref = _i.value;

      case 15:
        pkg = _ref;

        checkDep(pkg.name);

      case 17:
        context$1$0.next = 5;
        break;

      case 19:
        if (!foundDuplicated) {
          context$1$0.next = 26;
          break;
        }

        msg = "Found these duplicate packages:\n\n";

        for (_name in duplicatedPackages) {
          msg += "- " + _name + " x " + duplicatedPackages[_name] + "\n";
        }

        msg += "\nRecommend running `npm dedupe`";
        return context$1$0.abrupt("return", [false, msg]);

      case 26:
        return context$1$0.abrupt("return", [true, "No duplicate babel packages found"]);

      case 27:
      case "end":
        return context$1$0.stop();
    }
  }, null, this);
};

module.exports = exports["default"];