/*
 * @Author: tengmingxue 1473375109@qq.com
 * @Date: 2023-08-15 11:20:48
 * @LastEditors: tengmingxue 1473375109@qq.com
 * @LastEditTime: 2023-09-14 09:46:41
 * @FilePath: \xld-gis-admin\src\main.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import '/@/design/index.less';
// Register windi
import 'virtual:windi.css';
// Register icon sprite
import 'virtual:svg-icons-register';
import App from './App.vue';
import { createApp } from 'vue';
import { initAppConfigStore } from '/@/logics/initAppConfig';
import { setupErrorHandle } from '/@/logics/error-handle';
import { router, setupRouter } from '/@/router';
import { setupRouterGuard } from '/@/router/guard';
import { setupStore } from '/@/store';
import { setupGlobDirectives } from '/@/directives';
import { setupI18n } from '/@/locales/setupI18n';
import { registerGlobComp } from '/@/components/registerGlobComp';
import '/@/assets/iconfont/iconfont';
import { usePlatform } from './views/system/customize/hook/usePlatformInfo';
import { useWebSecurityPolicy } from './hooks/web/useWebSecurityPolicy';
import 'core-js/es/array/at';
import eventBus from './utils/eventBus';
import * as echarts from 'echarts';
window.eventBus = eventBus;

removeMenu();
if (eventBus) eventBus.on('userSysRemove', () => removeMenu())
function removeMenu() {
  var num = 0;
  var loopsjl = setInterval(() => {
    var dom = document.querySelectorAll(".ml-2.vben-simple-menu-sub-title");
    if (dom.length > 0) {
      for (var i = 0; i < dom.length; i++) {//
        var str = dom[i].innerHTML;
        var o = dom[i].style;
        if (str == '用户管理　　　．' || str == '系统管理　　　．' || str == '备份还原　　　．') {
          o.textOverflow = 'clip';
          o.width = '60px';
          if (str === '系统管理　　　．') o.display = 'inline-flex';
          num++
          if (num == 4) clearInterval(loopsjl), num = 0;
        }
      }
    }
  }, 100)
}

if (import.meta.env.DEV) {
  import('ant-design-vue/dist/antd.less');
}
async function bootstrap() {
  useWebSecurityPolicy();

  const app = createApp(App);
  app.config.globalProperties.$echarts = echarts;
  // Configure store
  setupStore(app);

  await usePlatform();

  // Initialize internal system configuration
  initAppConfigStore();

  // Register global components
  registerGlobComp(app);

  // Multilingual configuration
  await setupI18n(app);

  // Configure routing
  setupRouter(app);

  // router-guard
  setupRouterGuard(router);

  // Register global directive
  setupGlobDirectives(app);

  // Configure global error handling
  setupErrorHandle(app);

  // Mount when the route is ready
  // https://next.router.vuejs.org/api/#isready
  await router.isReady();

  app.mount('#app', true);
}

void bootstrap();

Array.prototype.remove = function (index) {
  if (index > -1) this.splice(index, 1)
  return this;
}