import LocaleUtil from "./../LocaleUtil";
import createDebugElement from "./createDebugElement";
import triggerClickLimit from "./triggerClickLimit";

// 内库使用-start
import Toast from "./../../components/Toast";
// 内库使用-end

/* 测试使用-start
import { Toast } from 'seedsui-react'
测试使用-end */

// 如果DB里存储debug, 则默认开启debug模式
if (window.sessionStorage.getItem('_debug_')) {
  window.top._debug_ = true;
}

// Debugger Tools
var Debugger = {
  debugVisible: undefined,
  // Add bind: click debug element 10 times and then show debug panel
  addTrigger: function addTrigger(container) {
    var _this = this;
    var target = container || document.getElementById('_debug_trigger_');
    if (!target) {
      target = createDebugElement();
    }
    if (!target) return;
    triggerClickLimit(target, 10, function () {
      _this.showDebug();
    });
  },
  // Show debug panel
  showDebug: function showDebug() {
    var _this2 = this;
    if (this.debugVisible) return true;
    return new Promise(function (resolve) {
      import('vconsole').then(function (VConsole) {
        var _VConsole;
        if ((_VConsole = VConsole) !== null && _VConsole !== void 0 && _VConsole.default) {
          // eslint-disable-next-line
          VConsole = VConsole.default;
        }
        window.top._debug_ = true;
        window.sessionStorage.setItem('_debug_', '1');
        _this2.debugVisible = new VConsole();
        resolve(true);
      }).catch(function (error) {
        Toast.show({
          content: LocaleUtil.locale('打开调试面板失败', 'SeedsUI_open_debugger_failed'),
          maskClickable: true
        });
        resolve(false);
      });
    });
  }
};
export default Debugger;