import { createApp } from 'vue'
import { createPinia } from 'pinia'
// 命令式调用不会经过组件自动按需引入，需显式保留其样式，避免提示退化为页面普通文本。
import 'element-plus/es/components/message/style/css'
import 'element-plus/es/components/message-box/style/css'
import 'element-plus/es/components/notification/style/css'
import './style.css'
import App from './App.vue'
import router from './router'
import { initializeAppUpdates } from './services/appUpdates'
import { initializeNativeHome } from './services/nativeHome'
import { setRouter } from './utils/navigate'
import { initializeAuthSession } from './auth/session'

const app = createApp(App)
app.use(createPinia())
app.use(router)
setRouter(router)
window.addEventListener('mingxu-session-expired', () => {
  const returnUrl = location.pathname + location.search + location.hash
  void router.push({ name: 'login', query: { redirect: returnUrl } })
})
initializeAuthSession()
app.mount('#app')
void initializeAppUpdates()
initializeNativeHome(router)
