'use strict';

Object.defineProperty(exports, "__esModule", {
  value: true
});

var _regenerator;

function _load_regenerator() {
  return _regenerator = _interopRequireDefault(require('babel-runtime/regenerator'));
}

var _bluebird;

function _load_bluebird() {
  return _bluebird = require('bluebird');
}

var _consumer;

function _load_consumer() {
  return _consumer = require('../../../consumer');
}

var _installComponents;

function _load_installComponents() {
  return _installComponents = require('../../../consumer/component-ops/install-components');
}

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

exports.default = function () {
  var _ref = (0, (_bluebird || _load_bluebird()).coroutine)( /*#__PURE__*/(_regenerator || _load_regenerator()).default.mark(function _callee(ids, verbose, packageManagerArgs) {
    var consumer, bitIds, installResults;
    return (_regenerator || _load_regenerator()).default.wrap(function _callee$(_context) {
      while (1) {
        switch (_context.prev = _context.next) {
          case 0:
            _context.next = 2;
            return (0, (_consumer || _load_consumer()).loadConsumer)();

          case 2:
            consumer = _context.sent;

            consumer.packageManagerArgs = packageManagerArgs;
            bitIds = ids.map(function (id) {
              return consumer.getParsedId(id);
            });

            if (!ids.length) {
              _context.next = 11;
              break;
            }

            _context.next = 8;
            return (0, (_installComponents || _load_installComponents()).installIds)(consumer, bitIds, verbose);

          case 8:
            _context.t0 = _context.sent;
            _context.next = 14;
            break;

          case 11:
            _context.next = 13;
            return (0, (_installComponents || _load_installComponents()).install)(consumer, verbose);

          case 13:
            _context.t0 = _context.sent;

          case 14:
            installResults = _context.t0;
            _context.next = 17;
            return consumer.onDestroy();

          case 17:
            return _context.abrupt('return', installResults);

          case 18:
          case 'end':
            return _context.stop();
        }
      }
    }, _callee, this);
  }));

  function installAction(_x, _x2, _x3) {
    return _ref.apply(this, arguments);
  }

  return installAction;
}();