import { createApp, type DefineComponent } from 'vue'
import request from '@/request'

import 'ant-design-vue/dist/reset.css'
import '@/styles/index.css'

import App from './App.vue'
import router from './router'
import pinia from '@/stores/index'

const app = createApp(App)

app.config.globalProperties.$http = request
app.use(pinia)
app.use(router)

const components = import.meta.glob('./components/**/*.vue', { eager: true })
Object.entries(components).forEach(([path, module]) => {
  const componentName =
    (module as { default: DefineComponent }).default?.name ||
    path
      .split('/')
      .pop()
      ?.replace(/\.\w+$/, '')
  if (componentName) {
    app.component(componentName, (module as { default: DefineComponent }).default)
  }
})

app.mount('#app')
