import {
	createRouter,
	createWebHashHistory
} from "vue-router";

import {
	getToken
} from "./utils/wxtools";

const router = createRouter({
	history: createWebHashHistory(),
	routes: [{
			path: "/",
			name: "Index",
			component: () => import("./views/index/index.vue"),
			meta: {
				needLogin: true,
			},
		},
		{
			path: "/ancestralHall",
			name: "AncestralHall",
			component: () => import("./views/sacrifice/ancestralHall/index.vue"),
		},
		{
			path: "/ancestralHallAdd",
			name: "AncestralHallAdd",
			component: () => import("./views/sacrifice/ancestralHall/add.vue"),
		},
		{
			path: "/genealogy",
			name: "Genealogy",
			component: () => import("./views/sacrifice/genealogy/index.vue"),
		},
		{
			path: "/genealogyAdd",
			name: "GenealogyAdd",
			component: () => import("./views/sacrifice/genealogy/add.vue"),
		},
		{
			path: "/photoAlbum",
			name: "PhotoAlbum",
			component: () => import("./views/sacrifice/photoAlbum/index.vue"),
		},
		{
			path: "/photoAlbumAdd",
			name: "PhotoAlbumAdd",
			component: () => import("./views/sacrifice/photoAlbum/add.vue"),
		},
		{
			path: "/fete",
			name: "Fete",
			component: () => import("./views/sacrifice/fete/index.vue"),
		},
		{
			path: "/family",
			name: "Family",
			component: () => import("./views/sacrifice/family/index.vue"),
		},
		{
			path: "/familyAdd",
			name: "FamilyAdd",
			component: () => import("./views/sacrifice/family/add.vue"),
		},
		{
			path: "/gaya",
			name: "Gaya",
			component: () => import("./views/sacrifice/gaya/index.vue"),
		},
		{
			path: "/gayaAdd",
			name: "GayaAdd",
			component: () => import("./views/sacrifice/gaya/add.vue"),
		},

		{
			path: "/events",
			name: "Events",
			component: () => import("./views/events/index.vue"),
		},
		{
			path: "/eventsAdd",
			name: "EventsAdd",
			component: () => import("./views/events/add.vue"),
		},
		{
			path: "/reg",
			name: "Reg",
			component: () => import("./views/wechart/reg.vue"),
		},
		{
			path: "/check",
			name: "Check",
			component: () => import("./views/wechart/check.vue"),
		},
		{
			path: "/user",
			name: "User",
			component: () => import("./views/user.vue"),
			meta: {
				needLogin: true,
			},
		},
		{
			path: "/user/info",
			name: "UserInfo",
			component: () => import("./views/user-info.vue"),
			meta: {
				//是否隐藏底部导航
				isHideTabBar: true,
			},
		}, ,
		
		{
			path: "/login",
			name: "Login",
			component: () => import("./views/wechart/wxlogin.vue"), //微信登录
			meta: {
				isHideTabBar: true,
			},
		},
		{
		  path: "/wxAuth",
		  name: "WxAuth",
		  component: () => import("./views/wechart/Auth.vue"),
		  meta: {
		  	needLogin: false,
		  	//是否隐藏底部导航
		  	isHideTabBar: true,
		  },
		}   
	],
});
//路由守卫-----
router.beforeEach((to, from, next) => {
	if (to.meta.needLogin) {
		if (getToken()) {
			next();
		} else {
			next({
				name: "Login",
			});
		}
	} else {
		next();
	}
});

export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router;