import { createApp } from 'vue';
import './style.css';
import App from './App.vue';
import { router } from './router'
import { store } from './store';
import Antd from 'ant-design-vue';
import 'ant-design-vue/dist/reset.css';


import { QuillEditor } from '@vueup/vue-quill'


import ACOperation from '@/components/cOperation/cOperation.vue';
import ACTable from '@/components/cTable/cTable.vue';
import ACCascader from '@/components/cCascader/cascader.vue';

import AShujilian from '@/components/form/shujilian.vue';
import SearchSelect from '@/components/form/search-select.vue';
import AXuanze from '@/components/cSelect/xuanze.vue';
import ACSelect from '@/components/cSelect/select.vue';
import ACSelectCommon from '@/components/cSelect/common.vue';
import UploadOne from '@/components/upload/one.vue';
import UploadFile from '@/components/upload/file.vue';
import ImageContainer from '@/components/form/image-container.vue';
import { Model } from 'node_modules/echarts/index';
// router.beforeEach(async (to, from, next) => {
// 	document.title = `${to.meta.title} - 菊城人才市场后台管理`;
// 	// 动态路由可能还没加载完成，先检查是否已加载
// 	if (store.state.permissions.permissionList == null) {
// 		debugger
// 		await store.dispatch('permissions/FETCH_PERMISSION');
// 	}

// 	// 这里假设有一个isAuth的getter来检查用户是否已登录
// 	if (sessionStorage.getItem('token')) {
// 		debugger
// 		next();
// 	} else {
// 		debugger
// 		next('/login');
// 	}

// });
router.beforeEach((to, from, next) => {
	document.title = `${to.meta.title} - 菊城人才市场后台管理`;
	if (!sessionStorage.getItem('token')) {
		if (to.matched.length > 0 && !to.matched.some(record => record.meta.requiresAuth)) {
			next()
		} else {
			next({
				path: '/login'
			})
		}
	} else {
		if (store.state.permissions.permissionList == null) {
			store.dispatch('permissions/FETCH_PERMISSION').then(() => {
				next({
					path: to.path
				})
			})
		} else {
			if (to.path !== '/login') {
				next()
			} else {
				next(from.fullPath)
			}
		}
	}
})

router.afterEach((to, from, next) => {
	let routerList = to.matched;
	
	store.commit('setCrumbList', routerList)
})

const app = createApp(App);
app.component('a-c-operation', ACOperation);
app.component('a-c-table', ACTable);
app.component('a-c-cascader', ACCascader);
app.component('a-c-select', ACSelect);
app.component('a-xuanze', AXuanze);
app.component('a-shujilian', AShujilian);
app.component('search-select', SearchSelect);
app.component('image-container', ImageContainer)
app.component('a-c-select-common', ACSelectCommon);
app.component('QuillEditor', QuillEditor)
app.component('upload-one', UploadOne)
app.component('upload-file', UploadFile)
app.use(router);
app.use(store);
app.use(Antd);
app.mount('#app');