import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
import _regeneratorRuntime from "@babel/runtime/regenerator";
import { setters, skeleton, material, plugins } from '../shell';
var PluginManager = /*#__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 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(pluginConfigCreator, options) {
      var config;
      return _regeneratorRuntime.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: setters,
              skeleton: skeleton,
              material: material,
              plugins: 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;
}();
export { PluginManager as default };