import {
  createRouter,
  createWebHistory,
  createWebHashHistory,
} from "vue-router";
import Layout from "@/layout/index.vue";
const router = createRouter({
  // history: createWebHashHistory("/carstop/dist6"), // 线上地址
  history: createWebHashHistory("/ride-sharing/pc"), // 校团环境发布地址
  routes: [
    {
      path: "/login",
      component: () => import("@/views/login/index.vue"),
    },
    {
      path: "/",
      redirect: "/login",
    },
    {
      path: "/schoolBus",
      component: Layout,
      children: [
        {
          path: "news",
          component: () => import("@/views/news/news.vue"),
          meta: { title: "Dashboard", icon: "dashboard" },
        },

        // 交通卡交易明细
        {
          path: "busDetail",
          component: () => import("@/views/busDetail/busDetail.vue"),
          meta: { title: "Dashboard", icon: "dashboard" },
        },
        // 交通卡管理
        {
          path: "busManagement",
          component: () => import("@/views/busManagement/busManagement.vue"),
          meta: { title: "Dashboard", icon: "dashboard" },
        },
        // 认证管理
        {
          path: "authentication",
          component: () => import("@/views/authentication/authentication.vue"),
          meta: { title: "Dashboard", icon: "dashboard" },
        },
        // 退款管理
        {
          path: "refund",
          component: () => import("@/views/refund/refund.vue"),
          meta: { title: "Dashboard", icon: "dashboard" },
        },
         // 交通卡设置
        {
          path: "busSet",
          component: () => import("@/views/busSet/busSet.vue"),
          meta: { title: "Dashboard", icon: "dashboard" },
        },

        {
          path: "statement",
          component: () => import("@/views/statement/statement.vue"),
          meta: { title: "Dashboard", icon: "dashboard" },
        },
        {
          path: "staff",
          component: () => import("@/views/staff/staff.vue"),
          meta: { title: "Dashboard", icon: "dashboard" },
        },
        {
          path: "account",
          component: () => import("@/views/account/account.vue"),
          meta: { title: "Dashboard", icon: "dashboard" },
        },
        {
          path: "bus",
          component: () => import("@/views/bus/bus.vue"),
          meta: { title: "Dashboard", icon: "dashboard" },
        },
        {
          path: "classes",
          component: () => import("@/views/classes/classes.vue"),
          meta: { title: "Dashboard", icon: "dashboard" },
        },
        {
          path: "buspath",
          component: () => import("@/views/buspath/buspath.vue"),
          meta: { title: "Dashboard", icon: "dashboard" },
        },
        // {
        //   path: "blacklist",
        //   component: () => import("@/views/blacklist/blacklist.vue"),
        //   meta: { title: "Dashboard", icon: "dashboard" },
        // },
        {
          path: "system",
          component: () => import("@/views/waiting/waiting.vue"),
          meta: { title: "Dashboard", icon: "dashboard" },
        },
        {
          path: "busquery",
          component: () => import("@/views/busquery/busquery.vue"),
          meta: { title: "Dashboard", icon: "dashboard" },
        },
        {
          path: "log",
          component: () => import("@/views/log/log.vue"),
          meta: { title: "Dashboard", icon: "dashboard" },
        },
        // 司机审核
        {
          path: "driverAudit",
          component: () => import("@/views/driver/audit.vue"),
          meta: { title: "Dashboard", icon: "dashboard" },
        },
        // 司机管理
        {
          path: "driverManagement",
          component: () => import("@/views/driver/management.vue"),
          meta: { title: "Dashboard", icon: "dashboard" },
        },
        // 司机提现管理
        {
          path: "driverDeposit",
          component: () => import("@/views/driver/deposit.vue"),
          meta: { title: "Dashboard", icon: "dashboard" },
        },
        // 优惠券管理
        {
          path: "coupon",
          component: () => import("@/views/driver/coupon.vue"),
          meta: { title: "Dashboard", icon: "dashboard" },
        },
        // 优惠券记录
        {
          path: "couponRecord",
          component: () => import("@/views/driver/couponRecord.vue"),
          meta: { title: "Dashboard", icon: "dashboard" },
        },
        // 路线管理
        {
          path: "driverPath",
          component: () => import("@/views/driver/path.vue"),
          meta: { title: "Dashboard", icon: "dashboard" },
        },
        // 订单管理
        {
          path: "driverOrder",
          component: () => import("@/views/driver/order.vue"),
          meta: { title: "Dashboard", icon: "dashboard" },
        },
        // 规则设置
        {
          path: "driverRule",
          component: () => import("@/views/driver/rule.vue"),
          meta: { title: "Dashboard", icon: "dashboard" },
        },
        {
          path: "report",
          component: () => import("@/views/report/report.vue"),
          meta: { title: "Dashboard", icon: "dashboard" },
        },
      ],
    },
  ],
});
export default router;
router.beforeEach((to, from, next) => {
  // 判断 如果cook是否存在，可以进去
  if (sessionStorage.getItem("token")) {
    next(); //放行
  } else {
    if (to.path == "/login") {
      next();
    } else {
      next(`/login`);
    }
  }
});
