'use strict';

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

var vConsole_config = require('../config.js');

function getCurrentEnv() {
  var value = window.sessionStorage.getItem(vConsole_config.DEBUG_CGI_ENV.KEY);
  console.log('value', value);
  if (value === vConsole_config.DEBUG_CGI_ENV.PROD) {
    return '正式';
  }
  if (value === vConsole_config.DEBUG_CGI_ENV.TEST) {
    return '测试';
  }
  return '默认';
}
function initSwitchEnvPlugin() {
  var tipPlugin = new VConsole.VConsolePlugin('switchEnv', '切换环境');
  var currentEnv = getCurrentEnv();
  var html = "<div class=\"".concat(vConsole_config.V_CONSOLE_DOM.WRAP, "\">\n<div class=\"").concat(vConsole_config.V_CONSOLE_DOM.LINE, "\">\u5F53\u524D\u73AF\u5883\uFF1A").concat(currentEnv, "</div>\n  </div>");
  tipPlugin.on('renderTab', function (callback) {
    callback(html);
  });
  tipPlugin.on('addTool', function (callback) {
    var toolList = [];
    toolList.push({
      name: '测试环境',
      global: false,
      onClick: function onClick() {
        console.log('已切换为测试CGI，即将刷新页面......');
        window.sessionStorage.setItem(vConsole_config.DEBUG_CGI_ENV.KEY, vConsole_config.DEBUG_CGI_ENV.TEST);
        setTimeout(function () {
          location.reload();
        }, 1000);
      }
    });
    toolList.push({
      name: '现网环境',
      global: false,
      onClick: function onClick() {
        console.log('已切换为正式CGI，即将刷新页面......');
        window.sessionStorage.setItem(vConsole_config.DEBUG_CGI_ENV.KEY, vConsole_config.DEBUG_CGI_ENV.PROD);
        setTimeout(function () {
          location.reload();
        }, 1000);
      }
    });
    callback(toolList);
  });
  return tipPlugin;
}

exports.initSwitchEnvPlugin = initSwitchEnvPlugin;
