import i18n from '@/locales'
import type { App } from 'vue'
import VXETable from 'vxe-table'
import 'vxe-table/lib/style.css'
import VxeUI from 'vxe-pc-ui'
import 'vxe-pc-ui/lib/style.css'
import VXETablePluginAntd from 'vxe-table-plugin-antd'
import VxeUIPluginRenderAntd from '@vxe-ui/plugin-render-antd'
import VxeUIPluginExportXLSX from '@vxe-ui/plugin-export-xlsx'
import ExcelJS from 'exceljs'

VxeUI.use(VxeUIPluginRenderAntd)
VxeUI.use(VxeUIPluginExportXLSX, { ExcelJS })

import XEUtils from 'xe-utils'
import 'vxe-table-plugin-antd/dist/style.css'

VXETable.use(VXETablePluginAntd).setConfig({
	// 对组件内置的提示语进行国际化翻译
	i18n: (key: string, args) => i18n.global.t(key, args),
	size: 'mini',
	//vxe-table 组件键值自动翻译
	translate(key: string, args) {
		// 例如，只翻译 "page." 开头的键值
		if (key && key.indexOf('page.') > -1) {
			return i18n.global.t(key, args)
		}
		return key
	},
})

XEUtils.mixin({
	guid: () => {
		return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
			const r = (Math.random() * 16) | 0,
				v = c == 'x' ? r : (r & 0x3) | 0x8
			return v.toString(16)
		})
	},
})
export default {
	install: (app: App) => {
		app.use(VXETable).use(VxeUI)
	},
}
