import { createApp } from 'vue'
import pinia from "./stores/index";
import router from "./router";
import './style.css'
import App from './App.vue'
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
import * as ElementPlusIconsVue from '@element-plus/icons-vue'
import { lissenLog, log } from './utils/log'
import useUserInfo from './stores/modules/user'

const app = createApp(App)
app.use(ElementPlus)
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
    app.component(key, component)
}
app.use(pinia)
app.use(router)

// 注册埋点指令和路由监听 - 确保在router使用后立即注册
lissenLog(app)
log(router)

app.mount('#app')

// 刷新后根据会话标记显示登录弹窗
try {
    const flag = sessionStorage.getItem('NEED_LOGIN_MODAL')
    if (flag) {
        const userStore = useUserInfo()
        userStore.updateLoginShow(true)
        sessionStorage.removeItem('NEED_LOGIN_MODAL')
    }
} catch {}
