import { V_CONSOLE_DOM, V_CONSOLE_NO_DELAY } from '../config.mjs';

function getCurrentState() {
  var value = window.sessionStorage.getItem(V_CONSOLE_NO_DELAY.KEY);
  if (value === V_CONSOLE_NO_DELAY.VALUE) {
    return '已去掉延迟';
  }
  return '默认';
}
function initLoadDelayPlugin() {
  var plugin = new VConsole.VConsolePlugin('loadDelay', 'vConsole加载延迟');
  var html = "<div class=\"".concat(V_CONSOLE_DOM.WRAP, "\">\n  <div class=\"").concat(V_CONSOLE_DOM.LINE, "\">\u5F53\u524D\u72B6\u6001\uFF1A").concat(getCurrentState(), "</div>\n    </div>");
  plugin.on('renderTab', function (callback) {
    callback(html);
  });
  var btnList = [];
  btnList.push({
    name: '去除延迟',
    global: false,
    onClick: function onClick() {
      sessionStorage.setItem(V_CONSOLE_NO_DELAY.KEY, V_CONSOLE_NO_DELAY.VALUE);
      console.log('已设置去除延迟，即将刷新页面......');
      setTimeout(function () {
        location.reload();
      }, 1000);
    }
  });
  btnList.push({
    name: '恢复延迟',
    global: false,
    onClick: function onClick() {
      sessionStorage.removeItem(V_CONSOLE_NO_DELAY.KEY);
      console.log('已设置恢复延迟，即将刷新页面......');
      setTimeout(function () {
        location.reload();
      }, 1000);
    }
  });
  btnList.push({
    name: '刷新页面',
    global: false,
    onClick: function onClick() {
      window.location.reload();
    }
  });
  plugin.on('addTool', function (callback) {
    callback(btnList);
  });
  return plugin;
}

export { initLoadDelayPlugin };
