import { createApp,defineAsyncComponent } from 'vue'
import Cookies from 'js-cookie'
import App from './App'
import store from './store'
import router from './router'
import directive from './directive' // directive 
import '@/assets/styles/index.scss' // global css
// 注册指令
import plugins from './plugins' // plugins
import { download } from '@/utils/request'
// svg图标
import 'virtual:svg-icons-register'
import SvgIcon from '@/components/SvgIcon'
import './permission' // permission control
import { useDict } from '@/utils/dict'
import { parseTime, resetForm, addDateRange, handleTree, selectDictLabel, selectDictLabels,downloadFile } from '@/utils/ruoyi'
// 自定义表格工具组件
import RightToolbar from '@/components/RightToolbar'
//role菜单权限选择逐渐
import Rolemenu from '@/components/Rolemenu'
import DictTag from '@/components/DictTag'
import util from '@/components-zbry/utils'

const app = createApp(App)
// 懒加载组件
const BaseTable = defineAsyncComponent(() => import('@/components-zbry/BaseTable'));
const BaseChildrenPage = defineAsyncComponent(() => import('@/components-zbry/BaseChildrenPage'));
const BaseFilter = defineAsyncComponent(() => import('@/components-zbry/BaseFilter'));
const BaseModel = defineAsyncComponent(() => import('@/components-zbry/BaseModel'));
const BaseSelect = defineAsyncComponent(() => import('@/components-zbry/BaseSelect'));
const BaseControl = defineAsyncComponent(() => import('@/components-zbry/BaseControl'));
const BaseTablePage = defineAsyncComponent(() => import('@/components-zbry/BaseTablePage'));
const BaseRadioGroup = defineAsyncComponent(() => import('@/components-zbry/BaseRadioGroup'));
const BaseUpload = defineAsyncComponent(() => import('@/components-zbry/BaseUpload'));
const BaseTree = defineAsyncComponent(() => import('@/components-zbry/BaseTree'));
const TagInput = defineAsyncComponent(() => import('@/components-zbry/TagInput'));
const Editor = defineAsyncComponent(() => import('@/components-zbry/Editor'));
const Bpmn = defineAsyncComponent(() => import('@/components-zbry/Bpmn'));
// const ProcessView = defineAsyncComponent(() => import('@/components-zbry/Bpmn/ProcessView'));
const weditor = defineAsyncComponent(() => import('@/components/editor'));
const formdataUpload = defineAsyncComponent(() => import('@/components/formdataUpload/formdataUpload.vue'));


app.component('BaseTable', BaseTable)
app.component('BaseChildrenPage', BaseChildrenPage)
app.component('BaseFilter', BaseFilter)
app.component('BaseModel', BaseModel)
app.component('BaseSelect', BaseSelect)
app.component('BaseControl', BaseControl)
app.component('BaseTablePage', BaseTablePage)
app.component('BaseRadioGroup', BaseRadioGroup)
app.component('BaseUpload', BaseUpload)
app.component('BaseTree', BaseTree)
app.component('TagInput', TagInput)
app.component('Editor', Editor)
app.component('Bpmn', Bpmn)
// app.component('ProcessView', ProcessView)
app.component("weditor", weditor);
app.component("formdataUpload", formdataUpload);
app.config.globalProperties.$util = util;


// ===================ruiyi组件============================
// 分页组件
import Pagination from '@/components/Pagination'
// // 文件上传组件
// import FileUpload from "@/components/FileUpload"
// // 图片上传组件
// import ImageUpload from "@/components/ImageUpload"
// // 图片预览组件
// import ImagePreview from "@/components/ImagePreview"
// 自定义树选择组件
// import TreeSelect from '@/components/TreeSelect'
app.component('Pagination', Pagination)
// app.component('TreeSelect', TreeSelect)
// app.component('FileUpload', FileUpload)
// app.component('ImageUpload', ImageUpload)
// app.component('ImagePreview', ImagePreview)
// ======================================================

app.component('Rolemenu', Rolemenu)
app.component('RightToolbar', RightToolbar)
app.component('DictTag', DictTag)
app.component('svg-icon', SvgIcon)
app.use(router)
app.use(store)
app.use(plugins)

//=======================================================
//              动态配置zbry初始化内容
//=======================================================
// app.config.globalProperties.$resPath = {//自定义tablePage接口的配置
//   tableResult: {//获取table数据的配置
//     successCode: 0,
//     codePath: 'data.code',
//     dataPath: 'data.data.list',
//     totalPath: 'data.data.total',
//     messagePath: 'data.msg',
//   },
//   rowResult: {//点击详情，获取行数据的配置
//       successCode: 0,
//       codePath: 'data.code',
//       dataPath: 'data.data',
//       messagePath: 'data.msg',
//   },
//   controlResult: {//修改/新增/删除的配置
//     successCode: 0,
//     codePath: 'data.code',
//     messagePath: 'data.msg'
//   }
// };
// app.config.globalProperties.$pageKeys = {
//   page: 'page',
//   limit: 'limit'
// };
//=======================================================

// 全局方法挂载
app.config.globalProperties.useDict = useDict
app.config.globalProperties.download = download
app.config.globalProperties.parseTime = parseTime
app.config.globalProperties.resetForm = resetForm
app.config.globalProperties.handleTree = handleTree
app.config.globalProperties.addDateRange = addDateRange
app.config.globalProperties.selectDictLabel = selectDictLabel
app.config.globalProperties.selectDictLabels = selectDictLabels
app.config.globalProperties.downfile = downloadFile
app.config.globalProperties.$register = async () => {
  const ElementPlus = await import('element-plus');
  const locale = await import('element-plus/lib/locale/lang/zh-cn');
  const elementIcons = await import("@/components/SvgIcon/svgicon");
  app.use(ElementPlus, {
    locale: locale.default,
    // 支持 large、default、small
    size: Cookies.get("size") || "default"
  });
  app.use(elementIcons.default)
}


directive(app)

app.mount('#app')
