import { createApp } from 'vue'
import { createPinia } from 'pinia'
import * as Sentry from '@sentry/vue'

import 'uno.css'

import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
import * as ElementPlusIconsVue from '@element-plus/icons-vue'
// import { install } from '@icon-park/vue-next/es/all'

import registerComponent from '@/components/index'
import directives from '@/directive'

import 'xe-utils'
import {
  // VXETable,
  Filter,
  Edit,
  Menu,
  Export,
  Keyboard,
  Validator,

  // 可选组件
  Icon,
  Column,
  Colgroup,
  // Grid,
  Tooltip,
  Toolbar,
  Pager,
  // Form,
  // FormItem,
  // FormGather,
  Checkbox,
  CheckboxGroup,
  Radio,
  RadioGroup,
  RadioButton,
  Switch,
  Input,
  Select,
  Optgroup,
  Option,
  // Textarea,
  Button,
  Modal,
  // List,
  // Pulldown,

  // 表格
  Table
} from 'vxe-table'
import 'vxe-table/styles/cssvar.scss'
import '@/utils/tableFormat'

import FsAdminCore from '@fskj-admin/core'
import '@fskj-admin/core/lib/style.css'

import App from './App.vue'
import router from './router'

import './assets/main.css'
import 'virtual:svg-icons-register'

import uploadConfig from './config/uploadConfig'

// import { ossUpload } from '@/utils/utils'

// import WujieVue from 'wujie-vue3'

function useTable(app: any) {
  // 表格功能
  app.use(Filter).use(Edit).use(Menu).use(Export).use(Keyboard).use(Validator)

  // 可选组件
  app
    .use(Icon)
    .use(Column)
    .use(Colgroup)
    // .use(Grid)
    .use(Tooltip)
    .use(Toolbar)
    .use(Pager)
    // .use(Form)
    // .use(FormItem)
    // .use(FormGather)
    .use(Checkbox)
    .use(CheckboxGroup)
    .use(Radio)
    .use(RadioGroup)
    .use(RadioButton)
    .use(Switch)
    .use(Input)
    .use(Select)
    .use(Optgroup)
    .use(Option)
    // .use(Textarea)
    .use(Button)
    .use(Modal)
    // .use(List)
    // .use(Pulldown)

    // 安装表格
    .use(Table)

  // 给 vue 实例挂载内部对象，例如：
  // app.config.globalProperties.$XModal = VXETable.modal
  // app.config.globalProperties.$XPrint = VXETable.print
  // app.config.globalProperties.$XSaveFile = VXETable.saveFile
  // app.config.globalProperties.$XReadFile = VXETable.readFile
}

const app = createApp(App)

app.use(createPinia())
app.use(router)
app.use(ElementPlus)
app.use(useTable)
app.use(FsAdminCore, {
  upload: uploadConfig
})
// app.use(WujieVue)
app.use(directives)
registerComponent(app)

for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
  app.component(key, component)
}

// install(app)

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
  })

app.mount('#app')
