import { createApp, watch } from 'vue'
import '@/assets/iconfont/iconfont.css'
import 'ant-design-vue/lib/message/style/index.less'
import './style.scss'
import App from './App.vue'
import { setupI18n, ui18n } from '@/lang'
import { router, enableRouteNames } from './router'
import { pinia, useProject, useUserStore } from './store'

export const app = createApp(App)
app.use(router)
app.use(pinia)
setupI18n(app)
app.mount('#app')

const userStore = useUserStore(pinia)
const projectStore = useProject(pinia)

watch(
  () =>
    Array.from(new Set([...userStore.roleMenus, ...projectStore.roleMenus])),
  nMenus => {
    enableRouteNames([...nMenus])
  },
  { flush: 'sync', immediate: true }
)

document.title = ui18n.t('sys.name')
