import { createApp } from 'vue'
import ElementPlus from 'element-plus'
import * as ElementPlusIconsVue from '@element-plus/icons-vue'
import en from 'element-plus/es/locale/lang/en'
import zhCn from 'element-plus/es/locale/lang/zh-cn'
import 'element-plus/dist/index.css'
import 'element-plus/theme-chalk/dark/css-vars.css'

import App from './App.vue'
import router from './router'
import pinia from './store'
import i18n from './locales'
import '@/assets/styles/index.scss'

import { useThemeStore } from './store/theme'

const app = createApp(App)

// 注册所有 Element Plus 图标
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
  app.component(key, component)
}

// 注册插件 (不再传递 locale，由 el-config-provider 控制)
app.use(ElementPlus, {
  locale: i18n.global.locale.value === 'zh-cn' ? zhCn : en
})
app.use(router)
app.use(pinia)
app.use(i18n)

// 初始化主题（必须在 pinia 注册后）
const themeStore = useThemeStore()
themeStore.applyTheme()

app.mount('#app')
