import type { App } from 'vue'
// import { install } from '@icon-park/vue-next/es/all'
import { System, Check, MenuFoldOne, MenuUnfoldOne, Logout, SettingTwo } from '@icon-park/vue-next'

import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
import * as ElementPlusIconsVue from '@element-plus/icons-vue'

import 'xe-utils'
import {
  VxeIcon,
  VxeLoading,
  // VxeGrid,
  VxeTooltip,
  // VxeToolbar,
  // VxePager,
  // VxeForm,
  // VxeFormItem,
  // VxeFormGather,
  // VxeCheckbox,
  // VxeCheckboxGroup,
  // VxeRadio,
  // VxeRadioGroup,
  // VxeRadioButton,
  // VxeSwitch,
  // VxeInput,
  // VxeSelect,
  // VxeOptgroup,
  // VxeOption,
  // VxeTextarea,
  VxeButton,
  // VxeButtonGroup,
  VxeModal
  // VxeDrawer,
  // VxeList,
  // VxePulldown
} from 'vxe-pc-ui'
import {
  VxeUI,
  VXETable,
  VxeTable,
  VxeColumn,
  VxeColgroup,
  // VxeGrid,
  VxeToolbar
} from 'vxe-table'
import VxeUIPluginRenderElement from '@vxe-ui/plugin-render-element'
import '@vxe-ui/plugin-render-element/dist/style.css'
import 'vxe-table/styles/cssvar.scss'
import 'vxe-pc-ui/styles/cssvar.scss'
// 导入默认的语言
import zhCN from 'vxe-pc-ui/lib/language/zh-CN'
import '@/utils/tableFormat'

// import WujieVue from 'wujie-vue3'
// import * as Sentry from '@sentry/vue'

const modules = import.meta.glob('./form/*.vue', { eager: true })

function LazyVxeUI(app: any) {
  app.use(VxeIcon)
  app.use(VxeLoading)
  // app.use(VxeVxeGrid)
  app.use(VxeTooltip)
  // app.use(VxeToolbar)
  // app.use(VxePager)
  // app.use(VxeForm)
  // app.use(VxeFormItem)
  // app.use(VxeFormGather)
  // app.use(VxeCheckbox)
  // app.use(VxeCheckboxGroup)
  // app.use(VxeRadio)
  // app.use(VxeRadioGroup)
  // app.use(VxeRadioButton)
  // app.use(VxeSwitch)
  // app.use(VxeInput)
  // app.use(VxeSelect)
  // app.use(VxeOptgroup)
  // app.use(VxeOption)
  // app.use(VxeTextarea)
  app.use(VxeButton)
  // app.use(VxeButtonGroup)
  app.use(VxeModal)
  // app.use(VxeDrawer)
  // app.use(VxeList)
  // app.use(VxePulldown)
}
function LazyVxeTable(app: any) {
  app.use(VxeTable)
  app.use(VxeColumn)
  app.use(VxeColgroup)
  // app.use(VxeGrid)
  app.use(VxeToolbar)
}

function registerComponent(app: App): void {
  // icon-park
  app.component('icon-system', System)
  app.component('icon-check', Check)
  app.component('icon-menu-fold-one', MenuFoldOne)
  app.component('icon-menu-unfold-one', MenuUnfoldOne)
  app.component('icon-logout', Logout)
  app.component('icon-setting-two', SettingTwo)
  // install(app)

  // element-plus
  app.use(ElementPlus)
  for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
    app.component(key, component)
  }

  // vxe-table
  VXETable.setI18n('zh-CN', zhCN)
  VXETable.setLanguage('zh-CN')
  VxeUI.use(VxeUIPluginRenderElement)
  app.use(LazyVxeUI)
  app.use(LazyVxeTable)

  // 动态注册form文件夹下的组件
  for (const key in modules) {
    const name = key.replace(/^\.\/form\/|\.vue/g, '')
    const component = (modules[key] as any).default
    app.component('El' + name, component)
  }

  // 微服务 wujie
  // app.use(WujieVue)

  // 监控 sentry
  // import.meta.env.VITE_SENTRY_DSN &&
  // Sentry.init({
  //   app,
  //   dsn: import.meta.env.VITE_SENTRY_DSN,
  //   integrations: [Sentry.browserTracingIntegration(), Sentry.replayIntegration()],
  //   tracesSampleRate: 1.0,
  //   tracePropagationTargets: [],
  //   replaysSessionSampleRate: 0.1,
  //   replaysOnErrorSampleRate: 1.0
  // })
}

export default registerComponent
