import './assets/main.css'

import { createApp } from 'vue'
import { createPinia } from 'pinia'
import App from './App.vue'
import router from './router'
import i18n from './i18n'
import { useUserStore } from '@/stores/user'

// Naive UI
import {
  create,
  NButton,
  NCard,
  NLayout,
  NLayoutHeader,
  NLayoutContent,
  NLayoutSider,
  NLayoutFooter,
  NMenu,
  NSpace,
  NGrid,
  NGridItem,
  NAvatar,
  NDropdown,
  NBreadcrumb,
  NBreadcrumbItem,
  NInput,
  NInputGroup,
  NForm,
  NFormItem,
  NSelect,
  NDatePicker,
  NTimePicker,
  NCheckbox,
  NRadio,
  NSwitch,
  NSlider,
  NRate,
  NUpload,
  NTransfer,
  NTable,
  NDataTable,
  NPagination,
  NTabs,
  NTabPane,
  NCollapse,
  NCollapseItem,
  NTree,
  NModal,
  NDrawer,
  NPopover,
  NTooltip,
  NAlert,
  NProgress,
  NSpin,
  NSkeleton,
  NEmpty,
  NResult,
  NStatistic,
  NTag,
  NBadge,
  NIcon,
  NDivider,
  NBackTop,
  NAffix,
  NCalendar,
  NColorPicker,
  NDescriptions,
  NDescriptionsItem,
  NList,
  NListItem,
  NThing,
  NSteps,
  NStep,
  NTimeline,
  NTimelineItem,
  NMessageProvider
} from 'naive-ui'

const naive = create({
  components: [
    NButton,
    NCard,
    NLayout,
    NLayoutHeader,
    NLayoutContent,
    NLayoutSider,
    NLayoutFooter,
    NMenu,
    NSpace,
    NGrid,
    NGridItem,
    NAvatar,
    NDropdown,
    NBreadcrumb,
    NBreadcrumbItem,
    NInput,
    NInputGroup,
    NForm,
    NFormItem,
    NSelect,
    NDatePicker,
    NTimePicker,
    NCheckbox,
    NRadio,
    NSwitch,
    NSlider,
    NRate,
    NUpload,
    NTransfer,
    NTable,
    NDataTable,
    NPagination,
    NTabs,
    NTabPane,
    NCollapse,
    NCollapseItem,
    NTree,
    NModal,
    NDrawer,
    NPopover,
    NTooltip,
    NAlert,
    NProgress,
    NSpin,
    NSkeleton,
    NEmpty,
    NResult,
    NStatistic,
    NTag,
    NBadge,
    NIcon,
    NDivider,
    NBackTop,
    NAffix,
    NCalendar,
    NColorPicker,
    NDescriptions,
    NDescriptionsItem,
    NList,
    NListItem,
    NThing,
    NSteps,
    NStep,
    NTimeline,
    NTimelineItem,
    NMessageProvider
  ]
})

const app = createApp(App)
const pinia = createPinia()

app.use(pinia)
app.use(router)
app.use(i18n)
app.use(naive)

// 初始化用户认证状态
const userStore = useUserStore()

// 异步初始化认证状态
const initializeApp = async () => {
  try {
    await userStore.initializeAuth()
  } catch (error) {
    console.error('初始化认证状态失败:', error)
  } finally {
    app.mount('#app')
  }
}

initializeApp()
