import { createRouter, createWebHashHistory } from "vue-router";
import DocumentAIIntroduction from "@/pages/main/views/homePage.vue";
import magicColor from "@/pages/main/views/ImageProcess/magicColor.vue";
import ocr from "@/pages/main/views/Recognize/ocr.vue";
import tableRec from "@/pages/main/views/Recognize/tableRec.vue";
import LayoutAnalysis from "@/pages/main/views/Detection/LayoutAnalysis.vue";

const router = createRouter({
  history: createWebHashHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: "/",
      name: "main",
      component: DocumentAIIntroduction,
    },
    {
      path: "/magicColor",
      name: "magicColor",
      component: magicColor,
    },
    {
      path: "/ocr",
      name: "ocr",
      component: ocr,
    },
    {
      path: "/tableRec",
      name: "tableRec",
      component: tableRec,
    },
    {
      path: "/LayoutAnalysis",
      name: "LayoutAnalysis",
      component: LayoutAnalysis,
    }
  ],
});

let isAuthenticated = false; // 初始化用户登录状态

function check_login()
{
  if (isAuthenticated) { // 根据需要判断用户是否已经登录
    return true;
  } else {
    isAuthenticated = true;
    return false;
  }
}

router.beforeEach((to, from, next) => {
  if (from.path === '/' && !check_login()) { // 如果目标路径为根路径，则放行请求
    next('/')
  } else { // 否则将目标路径重定向到根路径
    next()
  }
})

export default router;