'use strict';

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

var _regenerator;

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

var scopeList = function () {
  var _ref3 = _asyncToGenerator( /*#__PURE__*/(_regenerator || _load_regenerator()).default.mark(function _callee2(consumer, showAll, showRemoteVersion) {
    var componentsList;
    return (_regenerator || _load_regenerator()).default.wrap(function _callee2$(_context2) {
      while (1) {
        switch (_context2.prev = _context2.next) {
          case 0:
            (_loader || _load_loader()).default.start((_loaderMessages || _load_loaderMessages()).BEFORE_LOCAL_LIST);
            componentsList = new (_componentsList || _load_componentsList()).default(consumer);
            return _context2.abrupt('return', componentsList.listScope(showRemoteVersion, showAll));

          case 3:
          case 'end':
            return _context2.stop();
        }
      }
    }, _callee2, this);
  }));

  return function scopeList(_x2, _x3, _x4) {
    return _ref3.apply(this, arguments);
  };
}();

var _consumer;

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

var _scope;

function _load_scope() {
  return _scope = require('../../../scope');
}

var _loader;

function _load_loader() {
  return _loader = _interopRequireDefault(require('../../../cli/loader'));
}

var _loaderMessages;

function _load_loaderMessages() {
  return _loaderMessages = require('../../../cli/loader/loader-messages');
}

var _remote;

function _load_remote() {
  return _remote = _interopRequireDefault(require('../../../remotes/remote'));
}

var _componentsList;

function _load_componentsList() {
  return _componentsList = _interopRequireDefault(require('../../../consumer/component/components-list'));
}

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

function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; }

exports.default = function () {
  var _ref2 = _asyncToGenerator( /*#__PURE__*/(_regenerator || _load_regenerator()).default.mark(function _callee(_ref) {
    var scopeName = _ref.scopeName,
        showAll = _ref.showAll,
        showRemoteVersion = _ref.showRemoteVersion;
    var consumer, scope, remotes, remote;
    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;
            scope = consumer.scope;

            if (!scopeName) {
              _context.next = 12;
              break;
            }

            _context.next = 7;
            return scope.remotes();

          case 7:
            remotes = _context.sent;
            _context.next = 10;
            return remotes.resolve(scopeName, scope);

          case 10:
            remote = _context.sent;
            return _context.abrupt('return', remoteList(remote));

          case 12:
            return _context.abrupt('return', scopeList(consumer, showAll, showRemoteVersion));

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

  function list(_x) {
    return _ref2.apply(this, arguments);
  }

  return list;
}();

function remoteList(remote) {
  (_loader || _load_loader()).default.start((_loaderMessages || _load_loaderMessages()).BEFORE_REMOTE_LIST);
  return remote.list();
}