"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports["default"] = void 0;
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
var _shell = require("../shell");
var PluginManager = exports["default"] = /*#__PURE__*/function () {
  function PluginManager() {
    this.pluginMap = new Map();
  }
  var _proto = PluginManager.prototype;
  _proto.getPluginMap = function getPluginMap() {
    return new Map(this.pluginMap);
  };
  _proto["delete"] = function _delete(pluginName) {
    this.pluginMap["delete"](pluginName);
  };
  _proto.register = /*#__PURE__*/function () {
    var _register = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee(pluginConfigCreator, options) {
      var config;
      return _regenerator["default"].wrap(function _callee$(_context) {
        while (1) switch (_context.prev = _context.next) {
          case 0:
            if (!this.pluginMap.get(pluginConfigCreator.pluginName)) {
              _context.next = 2;
              break;
            }
            return _context.abrupt("return", Promise.reject(pluginConfigCreator.pluginName + "\u5DF2\u7ECF\u5B58\u5728"));
          case 2:
            config = pluginConfigCreator({
              setters: _shell.setters,
              skeleton: _shell.skeleton,
              material: _shell.material,
              plugins: _shell.plugins
            }, options);
            _context.next = 5;
            return config.init();
          case 5:
            this.pluginMap.set(pluginConfigCreator.pluginName, {
              options: options,
              config: config,
              pluginName: pluginConfigCreator.pluginName
            });
            return _context.abrupt("return", Promise.resolve());
          case 7:
          case "end":
            return _context.stop();
        }
      }, _callee, this);
    }));
    function register(_x, _x2) {
      return _register.apply(this, arguments);
    }
    return register;
  }();
  return PluginManager;
}();