'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 _capsule;

function _load_capsule() {
  return _capsule = _interopRequireDefault(require('../../components/core/capsule'));
}

var _fsContainer;

function _load_fsContainer() {
  return _fsContainer = _interopRequireDefault(require('../../components/container/fs-container'));
}

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 _callee2() {
    var type = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'fs';
    var dir = arguments[1];
    var containerFactory, capsule, getContainerFactory;
    return (_regenerator || _load_regenerator()).default.wrap(function _callee2$(_context2) {
      while (1) {
        switch (_context2.prev = _context2.next) {
          case 0:
            getContainerFactory = function getContainerFactory() {
              var _this = this;

              switch (type) {
                case 'fs':
                default:
                  return (0, (_bluebird || _load_bluebird()).coroutine)( /*#__PURE__*/(_regenerator || _load_regenerator()).default.mark(function _callee() {
                    return (_regenerator || _load_regenerator()).default.wrap(function _callee$(_context) {
                      while (1) {
                        switch (_context.prev = _context.next) {
                          case 0:
                            return _context.abrupt('return', new (_fsContainer || _load_fsContainer()).default(dir));

                          case 1:
                          case 'end':
                            return _context.stop();
                        }
                      }
                    }, _callee, _this);
                  }));
              }
            };

            containerFactory = getContainerFactory();
            _context2.next = 4;
            return (_capsule || _load_capsule()).default.create(containerFactory);

          case 4:
            capsule = _context2.sent;
            _context2.next = 7;
            return capsule.start();

          case 7:
            return _context2.abrupt('return', capsule);

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

  function createCapsule() {
    return _ref.apply(this, arguments);
  }

  return createCapsule;
}();