import { createApp } from 'vue';
import App from './App.vue';
import router from './router';
import store from './store';
import Request from '@/utils/request';
import '@/router/permission.js';
import '@/assets/font/iconfont.css';
import { ElMessage } from 'element-plus';
import { defineRule, configure } from 'vee-validate';
import all from '@vee-validate/rules';
import allValid from '@/utils/validate';
import 'element-plus/dist/index.css';
import '@/assets/style/global.scss';
import ElementPlus from 'element-plus';
import htmlToPdf from '@/utils/htmlToPdf';
import zhCn from 'element-plus/es/locale/lang/zh-cn';
import {
	toolBtn,
	InputMini,
	operaRecorde,
	DetailsOperation,
	PrintModel,
	prtMoled,
} from '@/components/index';
import 'xe-utils';
import VXETable from 'vxe-table';
import 'vxe-table/lib/style.css';
import 'font-awesome/css/font-awesome.css';

// import
import Clipboard from 'clipboard';
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);
// 全局注册组件
app.component('toolBtn', toolBtn);
app.component('InputMini', InputMini);
app.component('operaRecorde', operaRecorde);
app.component('DetailsOperation', DetailsOperation);
app.component('PrintModel', PrintModel);
app.component('prtMoled', prtMoled);

app.use(store);
app.use(router);
app.use(htmlToPdf);
app.use(VXETable);
// 化汉
app.use(ElementPlus, {
	locale: zhCn,
});

app.config.globalProperties.$clipboard = Clipboard;
app.config.globalProperties.$http = new Request();
app.config.globalProperties.$message = ElMessage;
app.config.globalProperties.$close = function () {
	store.dispatch('topNavTag/close');
};
app.mount('#app');

// app.on('ready',function() {
//   mainwindow = new BrowserWindow({
//   width: 400,
//   height: 300,
//   webPreferences: {
//     nodeIntegration : true,
//     contextIsolation: false
//   }
// })

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

app.config.globalProperties.$commonData = {};

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