import { ref } from 'vue';
import { useAsRouter } from './useAsRouter'
import { store } from '@/store'

export const useMenu = () => {
	const { routerTo, routerCur, routerArrayCur,
		routerArrayParentChildCur } = useAsRouter();

	const openSubMenu = ref<string[]>([]);

	// 点击菜单获取路由
	const onMenu = (path) => {
		if (path == '/personal') {
			sessionStorage.setItem('mode', 'jokseeker')
			routerTo(path);
		} else if (path == '/jobseeker/search') {
			store.commit('getPageType', {
				pageType: ''
			})
			store.commit('setShowLoginBox', {
				showLoginBox: false
			})
			sessionStorage.setItem('pageType', '')
			store.commit('permissions/SET_PERMISSION', null)
			store.commit('permissions/SET_MENU', [])
			routerTo('/personal');
		} else {
			routerTo(path);
		}
		
	};


	return {
		routerCur,
		routerArrayCur,
		routerArrayParentChildCur,
		openSubMenu,
		onMenu,
	}
}