import { createApp } from 'vue';
import { createPinia } from 'pinia';
import App from '@/App.vue';
import router from '@/router';
import ElementPlus from 'element-plus';
import zhCn from 'element-plus/es/locale/lang/zh-cn';
import * as ElementPlusIconsVue from '@element-plus/icons-vue';
import 'element-plus/dist/index.css';
import 'element-plus/theme-chalk/dark/css-vars.css';
import '@/assets/styles/main.scss';
import '@/assets/styles/common.scss';
import VxeUIAll from 'vxe-pc-ui';
import 'vxe-pc-ui/es/style.css';
import VxeTable, { VxeUI } from 'vxe-table';
import 'vxe-table/lib/style.css';
import { initThemeColor } from '@/utils/theme';
import { useDark } from '@vueuse/core';
import i18n from '@/utils/i18n';

const isDark = useDark();
i18n.global.locale = (localStorage.getItem('LANG_LOCALE') || 'ZH') as 'ZH' | 'EN';

VxeUI.setTheme(isDark.value ? 'dark' : 'light');
initThemeColor();

const app = createApp(App);

// 全局引入图标
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
  app.component(key, component);
}

app.use(createPinia());
app.use(router);
app.use(VxeUIAll);
app.use(VxeTable);
app.use(i18n);
app.use(ElementPlus, {
  locale: zhCn,
});
app.mount('#app');
