'use strict';

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

var dom_dom = require('../dom/dom.js');
var loader_loader = require('../loader/loader.js');
var vConsole_config = require('./config.js');
var vConsole_plugin_delay = require('./plugin/delay.js');
var vConsole_plugin_env = require('./plugin/env.js');
var vConsole_plugin_feedback = require('./plugin/feedback.js');
var vConsole_plugin_msdk = require('./plugin/msdk.js');
var vConsole_plugin_version = require('./plugin/version.js');
var vConsole_plugin_versionSimple = require('./plugin/version-simple.js');
require('../loader/little-loader.js');
require('../clipboard/clipboard-web.js');
require('@babel/runtime/helpers/toConsumableArray');
require('../time/time.js');

/**
 * 加载 vConsole
 * @param {Object} [options = {}] vConsole 选项
 * @param {Array<string>} [plugins = []] 插件列表
 * @returns {Promise<Object>} vConsole 实例
 *
 * @example
 * ```ts
 * loadVConsole()
 * ```
 */
function loadVConsole() {
  var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  var plugins = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
  return new Promise(function (resolve) {
    if (typeof window.VConsole === 'undefined') {
      loader_loader.loadJS(vConsole_config.V_CONSOLE_URL).then(function () {
        resolve(initVConsole(options, plugins));
      });
    } else {
      resolve(initVConsole(options, plugins));
    }
  });
}
function initVConsole(options, plugins) {
  var vConsole = new VConsole(Object.assign({}, options || {}));
  vConsole.addPlugin(vConsole_plugin_version.initVersionPlugin());
  vConsole.addPlugin(vConsole_plugin_feedback.initFeedbackPlugin());
  vConsole.addPlugin(vConsole_plugin_env.initSwitchEnvPlugin());
  vConsole.addPlugin(vConsole_plugin_delay.initLoadDelayPlugin());
  vConsole.addPlugin(vConsole_plugin_versionSimple.initVersionSimplePlugin());
  vConsole.addPlugin(vConsole_plugin_msdk.initMsdkPlugin());
  plugins.forEach(function (plugin) {
    vConsole.addPlugin(plugin());
  });
  dom_dom.insertStyle({
    id: 'vConsolePluginStyle',
    content: vConsole_config.V_CONSOLE_STYLE_CONTENT
  });
  if (window && !window.vConsole) {
    window.vConsole = vConsole;
  }
  return vConsole;
}

exports.loadVConsole = loadVConsole;
