import {
  createApp
} from 'vue'
import JxOricoTable from 'jx-orico-com-table'
import 'jx-orico-com-table/lib/jx-orico-com-table.css'
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
import * as ElementPlusIconsVue from '@element-plus/icons-vue'
import App from './App.vue'
import router from './router'
import store from './store'
import Request from '@/utils/request'
import '@/router/permission.js'
import {
  ElMessage,
  ElLoading,
  ElMessageBox
} from 'element-plus'
import locale from 'element-plus/lib/locale/lang/zh-cn' //需要新加的代码
import {
  defineRule,
  configure
} from 'vee-validate'
// import all from '@vee-validate/rules'
// import allValid from '@/utils/validate'
import '@/assets/style/global.scss'
import '@/assets/style/icon.scss'
import '@/utils/iconfont.js'
import 'xe-utils'
import VXETable from 'vxe-table'
import 'vxe-table/lib/style.css'
import lcProject from './components/lcProject/index'
import debounce from './utils/debounce'
configure({
  validateOnBlur: true, // controls if `blur` events should trigger validation with `handleChange` handler
  validateOnChange: true, // controls if `change` events should trigger validation with `handleChange` handler
  validateOnInput: false, // controls if `input` events should trigger validation with `handleChange` handler
  validateOnModelUpdate: true // controls if `update:modelValue` events should trigger validation with `handleChange` handler
})
// Object.keys(all).forEach(rule => {
//   defineRule(rule, all[rule])
// })
// Object.keys(allValid).forEach(rule => {
//   defineRule(rule, allValid[rule])
// })

const app = createApp(App)

// 全局注册el-icon
for (const [name, component] of Object.entries(ElementPlusIconsVue)) {
  app.component(name, component)
}

app.use(store)
app.use(lcProject)
app.use(router)
app.use(ElMessage)
app.use(ElLoading)
app.use(ElementPlus, {
  locale
}) //需要改变的地方，加入locale
app.use(VXETable)
app.use(JxOricoTable)

app.config.globalProperties.$topNavTagRename = function (title) {
  store.dispatch('topNavTag/rename', title)
}

app.config.globalProperties.$http = new Request()
app.config.globalProperties.$message = ElMessage
app.config.globalProperties.$messageBox = ElMessageBox
app.config.globalProperties.$loading = ElLoading
app.config.globalProperties.$createSpuFresh = false
app.mixin(debounce)
app.mount('#app')

// 注册一个全局自定义指令 `v-allow` 配合路由meta.permission信息控制节点显示权限
app.directive('allow', {
  mounted(el, binding) {
    // console.log('`v-allow', binding.instance.$route.meta.permission)
    const permission = binding.instance.$route.meta.permission
    if (!permission.includes(binding.value)) {
      el.parentNode.removeChild(el)
    }
  }
})