import { createRouter, createWebHistory, RouteRecordRaw } from "vue-router";

/**
 * 基础路由配置（无需权限）
 */
export const routes: Array<RouteRecordRaw> = [
  {
    path: "/",
    redirect: "/home",
  },
  {
    path: "/login",
    component: () => import("@/layouts/BlankLayout.vue"),
    children: [
      {
        path: "",
        name: "Login",
        component: () => import("@/views/login/Login.vue"),
        meta: {
          title: "登录",
          requiresAuth: false,
          menuType: 3,
        },
      }
    ],
  },
  {
    path: "/register", 
    component: () => import("@/layouts/BlankLayout.vue"),
    children: [
      {
        path: "",
        name: "Register",
        component: () => import("@/views/login/Register.vue"),
        meta: {
          title: "注册",
          requiresAuth: false,
          menuType: 3,
        },
      }
    ],
  },
  {
    path: "/forgot-password",
    component: () => import("@/layouts/BlankLayout.vue"),
    children: [
      {
        path: "",
        name: "ForgotPassword",
        component: () => import("@/views/login/ForgotPassword.vue"),
        meta: {
          title: "忘记密码",
          requiresAuth: false,
          menuType: 3,
        },
      }
    ],
  },
  // 首页（显示在导航栏）
  // {
  //   path: "/home",
  //   component: () => import("@/layouts/NavigationLayout.vue"),
  //   children: [
  //     {
  //       path: "",
  //       name: "Home",
  //       component: () => import("@/views/HomeView.vue"),
  //       meta: {
  //         title: "首页",
  //         requiresAuth: false,
  //         menuType: 1, // NAVIGATION 类型，显示在顶部导航栏
  //         orderNum: -1, // 排在动态路由之前
  //       },
  //     }
  //   ],
  // },
  // 错误页面
  {
    path: "/403",
    component: () => import("@/layouts/BlankLayout.vue"),
    children: [
      {
        path: "",
        name: "Forbidden",
        component: () => import("@/views/error/403.vue"),
        meta: {
          title: "403 - 无权限访问",
          requiresAuth: false,
          menuType: 3,
        },
      }
    ],
  },
  {
    path: "/404", 
    component: () => import("@/layouts/BlankLayout.vue"),
    children: [
      {
        path: "",
        name: "NotFound",
        component: () => import("@/views/error/404.vue"),
        meta: {
          title: "404 - 页面不存在",
          requiresAuth: false,
          menuType: 3,
        },
      }
    ],
  },
  {
    path: "/500",
    component: () => import("@/layouts/BlankLayout.vue"),
    children: [
      {
        path: "",
        name: "ServerError",
        component: () => import("@/views/error/500.vue"),
        meta: {
          title: "500 - 服务器错误",
          requiresAuth: false,
          menuType: 3,
        },
      }
    ],
  },
  // 捕获所有未匹配的路由（这个应该在所有动态路由添加后再匹配）
  // 注意：404路由会在动态路由生成后重新添加
  // {
  //   path: "/:pathMatch(.*)*",
  //   redirect: "/404",
  // },
];

const router = createRouter({
  history: createWebHistory('/schoolNewsWeb/'),
  routes,
});

export default router;
