import { createApp } from 'vue'
import App from './App.vue'
import router from './router'
import { createPinia } from 'pinia'
import Antd from 'ant-design-vue'
import { ConfigProvider } from 'ant-design-vue'
import 'ant-design-vue/dist/reset.css'
import dayjs from 'dayjs'
import './mock' // 导入mock服务
import 'dayjs/locale/zh-cn'
import relativeTime from 'dayjs/plugin/relativeTime'
import duration from 'dayjs/plugin/duration'
import zhCN from 'ant-design-vue/es/locale/zh_CN'

// 配置 dayjs
dayjs.extend(relativeTime)
dayjs.extend(duration)
dayjs.locale('zh-cn')

// 为 Ant Design Vue 配置日期库
globalThis.dayjs = dayjs

// 创建应用实例
const app = createApp(App)
// 创建 Pinia 实例
const pinia = createPinia()

app.use(router)
app.use(pinia)
app.use(Antd)

// 配置 Ant Design Vue
app.use(ConfigProvider, {
  locale: zhCN,
  // 明确配置日期库为dayjs
  dateFormatter: 'dayjs',
  // 提供完整配置的dayjs实例，确保在组件中能正确访问到配置好的dayjs
  getDayjsInstance: () => {
    // 确保返回一个已经正确配置了语言和插件的dayjs实例
    return dayjs
  },
  // 安全地获取弹出层容器，防止trigger为null导致的错误
  getPopupContainer: (trigger) => trigger?.parentElement || document.body
})

app.mount('#app')