import { ElMessage } from "element-plus";
import { createRouter, createWebHashHistory } from "vue-router";
import { user } from '~/store/user';

const router = createRouter({
  history: createWebHashHistory(),
  routes: [
    {
      path: "",
      redirect: "/home",
    },
    {
      path: "/home",
      name: "home",
      title: "首页",
      component: () => import("~/pages/home/index.vue"),
    },
    {
      path: "/message",
      title: "系统消息",
      name: "message",
      component: () => import("~/pages/message/index.vue"),
    },
    //智慧教研首页
    {
      path: "/zhjy",
      name: "zhjy",
      component: () => import("~/pages/zhjy/index.vue"),
    },
    //自主研学
    {
      path: "/zhjy/zhjyzxxx",
      name: "zhjy_zhjyzxxx",
      component: () => import("~/pages/zhjy/zhjyzxxx/index.vue"),
    },
    {
      path: "/zhjy/zhjyzxxx/zxxxzy/:id",
      name: "zhjy_zhjyzxxx_zxxxzy",
      component: () => import("~/pages/zhjy/zhjyzxxx/zy-list.vue"),
    },
    {
      path: "/zhjy/zhjyzxxx/zxxxxq/:id",
      name: "zhjy_zhjyzxxx_zxxxxq",
      component: () => import("~/pages/zhjy/zhjyzxxx/zxxxxq/index.vue"),
    },
    {
      path: "/zhjy/zhjyzxxx/zxxxsp/:id",
      name: "zhjy_zhjyzxxx_zxxxsp",
      component: () => import("~/pages/zhjy/zhjyzxxx/zxxxsp/index.vue"),
    },

    //协同备课
    {
      path: "/zhjy/zhjyxtbk",
      name: "zhjy_zhjyxtbk",
      component: () => import("~/pages/zhjy/zhjyxtbk/index.vue"),
    },
    {
      path: "/zhjy/zhjyxtbk/nrxq/:id",
      name: "zhjy_zhjyxtbk_nrxq",
      component: () => import("~/pages/zhjy/zhjyxtbk/nrxq/index.vue"),
    },
    //同步教研
    {
      path: "/zhjy/zhjytbjy",
      name: "zhjy_zhjytbjy",
      component: () => import("~/pages/zhjy/zhjytbjy/index.vue"),
    },
    {
      path: "/zhjy/zhjytbjy/tbjynr",
      name: "zhjy_zhjytbjy_tbjynr",
      component: () => import("~/pages/zhjy/zhjytbjy/tbjynr/index.vue"),
    },
    {
      path: "/zhjy/zhjytbjy/detail/:id",
      name: "zhjy_tbjy_detail",
      component: () => import("~/pages/zhjy/tbjy/detail.vue"),
      props: true,
    },
    //艺术广场
    {
      path: "/ysgc",
      name: "ysgc",
      component: () => import("~/pages/ysgc/index.vue"),
    },
    {
      path: "/ysgc_kc/:id",
      name: "ysgc_kc",
      component: () => import("~/pages/ysgc/xskc.vue"),
    },
    {
      path: "/ysgc/stuDetail/:id",
      name: "ysgc_stuDetail",
      component: () => import("~/pages/ysgc/stuDetail/index.vue"),
    },
    {
      path: "/ysgc/jsDetail/:id",
      name: "ysgc_jsDetail",
      component: () => import("~/pages/ysgc/jsDetail/index.vue"),
    },
    {
      path: "/ysgc/schoolList/:id",
      name: "ysgc_schoolList",
      component: () => import("~/pages/ysgc/schoolList/index.vue"),
    },
    {
      path: "/ysgc/schoolZp/:id",
      name: "ysgc_schoolZp",
      component: () => import("~/pages/ysgc/schoolZp/index.vue"),
    },
    {
      path: "/ysgc/zpDetail/:id",
      name: "ysgc_zpDetail",
      component: () => import("~/pages/ysgc/zpDetail/index.vue"),
    },

    {
      path: "/ysgc",
      name: "ysgc",
      component: () => import("~/pages/ysgc/index.vue"),
    },
    // {
    // 	path: '/ysgc_detail',
    // 	name: 'ysgc_detail',
    // 	component: () => import('~/pages/ysgc/ysgc_detail/index.vue')
    // },
    {
      path: "/szmsg",
      children: [
        {
          path: "",
          name: "szmsg",
          component: () => import("~/pages/szmsg/index.vue"),
        },
        {
          path: "tzkc",
          children: [
            {
              path: "",
              name: "szmsg_tzkc",
              component: () => import("~/pages/szmsg/tzkc/index.vue"),
            },
            {
              path: "detail/:id",
              name: "szmsg_tzkc_detail",
              component: () => import("~/pages/szmsg/tzkc/detail/index.vue"),
              props: true,
            },
          ],
        },
        {
          path: "/yslm",
          name: "szmsg_yslm",
          component: () => import("~/pages/szmsg/yslm/index.vue"),
        },
        {
          path: "/yswz",
          name: "szmsg_yswz",
          component: () => import("~/pages/szmsg/yswz/index.vue"),
        },
        {
          path: "zjcm",
          name: "szmsg_zjcm",
          component: () => import("~/pages/szmsg/zjcm/index.vue"),
        },
      ],
    },

    {
      path: "/resource",
      name: "resource",
      title: "首页",
      component: () => import("~/pages/courseResources.vue"),
    },
    {
      path: "/resourceAll",
      name: "resourceAll",
      title: "首页",
      component: () => import("~/pages/courseResourcesAll.vue"),
    },
    {
      path: "/zbkt",
      title: "直播课堂",
      children: [
        {
          path: "",
          name: "zbkt",
          component: () => import("~/pages/zbkt/index.vue"),
        },
        {
          path: "ssys",
          children: [
            {
              path: ":status",
              name: "ssys",
              component: () => import("~/pages/zbkt/ssys/index.vue"),
              props: true,
            },
            {
              path: "content/:id/:status",
              name: "ssys_content",
              component: () => import("~/pages/zbkt/ssys/content.vue"),
              props: true,
            },
            {
              path: "rtc/:id",
              name: "ssys_rtc",
              component: () => import("~/pages/zbkt/ssys/rtc.vue"),
              props: true,
            },
            {
              path: "video/:id/:status",
              name: "ssys_video",
              component: () => import("~/pages/zbkt/ssys/video.vue"),
              props: true,
            },
          ],
        },
        {
          path: "wlzb",

          children: [
            {
              path: "",
              name: "wlzb",
              component: () => import("~/pages/zbkt/wlzb/index.vue"),
            },
            {
              path: "content/:id",
              name: "wlzb_content",
              component: () => import("~/pages/zbkt/wlzb/content.vue"),
            },
            {
              path: "detail/:id",
              name: "wlzb_detail",
              component: () => import("~/pages/zbkt/wlzb/detail.vue"),
            },
          ],
        },
        {
          path: "ztzb",
          children: [
            {
              path: "",
              name: "ztzb",
              component: () => import("~/pages/zbkt/ztzb/index.vue"),
            },
            {
              path: "content/:id",
              name: "ztzb_content",
              component: () => import("~/pages/zbkt/ztzb/content.vue"),
            },
          ],
        },
      ],
    },
    {
      path: "/resourceChapter",
      name: "resourceChapter",
      title: "课程资源章节",
      component: () => import("~/pages/courseResourcesChapter.vue"),
    },
    {
      path: "/resourceChapterList",
      name: "resourceChapterList",
      title: "课程资源章节",
      component: () => import("~/pages/courseResourcesChapterList.vue"),
    },
    {
      path: "/resourceFileReview",
      name: "resourceFileReview",
      title: "课程资源文件预览",
      component: () => import("~/pages/resourceFileReview.vue"),
    },
    {
      path: "/resourceMovReview",
      name: "resourceMovReview",
      title: "课程资源视频预览",
      component: () => import("~/pages/resourceMovReview.vue"),
    },

    {
      path: "/personal",
      name: "personal",
      title: "个人中心",
      component: () => import("~/pages/personal/index.vue"),
      redirect: "/personal/mycourse",
      children: [
        {
          path: "mycourse",
          name: "mycourse",
          title: "我的课程",
          component: () =>
            import("~/pages/personal/components/MyCourse/index.vue"),
        },
        {
          path: "course-ssys",
          name: "course-ssys",
          title: "全景课堂",
          component: () =>
            import("~/pages/personal/components/MyCourse/ssys.vue"),
        },
        {
          path: "course-ssys-create",
          name: "course-ssys-create",
          title: "创建全景课堂",
          component: () =>
            import("~/pages/personal/components/MyCourse/ssys-create.vue"),
        },
        {
          path: "course-ssys-detail/:id",
          name: "course-ssys-detail",
          title: "详情",
          component: () =>
            import("~/pages/personal/components/MyCourse/ssys-detail.vue"),
        },
        {
          path: "course-wlzb",
          name: "course-wlzb",
          title: "名师优课",
          // component: () => import("~/pages/personal/components/MyCourse/wlzb.vue"),
          redirect: {
            name: "personal_create_wlzb",
          },
        },
        {
          path: "course-ztzb",
          name: "course-ztzb",
          title: "艺术现场",
          // component: () => import("~/pages/personal/components/MyCourse/ztzb.vue"),
          redirect: {
            name: "personal_create_ztzb",
          },
        },
        {
          path: "course-xtbk",
          name: "course-xtbk",
          title: "协同备课",
          component: () =>
            import("~/pages/personal/components/MyCourse/xtbk.vue"),
        },
        {
          path: "xtbk-create",
          name: "xtbk-create",
          component: () =>
            import("~/pages/personal/components/MyCourse/xtbk-create.vue"),
        },
        {
          path: "course-tbjy",
          name: "course-tbjy",
          title: "同步教研",
          component: () =>
            import("~/pages/personal/components/MyCourse/tbjy.vue"),
        },
        {
          path: "tbjy-create",
          name: "tbjy-create",
          component: () =>
            import("~/pages/personal/components/MyCourse/tbjy-create.vue"),
        },
        {
          path: "course-zxxx",
          name: "course-zxxx",
          title: "自主研学",
          component: () =>
            import("~/pages/personal/components/MyCourse/zxxx.vue"),
        },
        {
          path: "zxxx-create",
          name: "zxxx-create",
          component: () =>
            import("~/pages/personal/components/MyCourse/zxxx-create.vue"),
        },
        {
          path: "zxxx-create_zy/:id",
          name: "zxxx-create-zy",
          component: () =>
            import("~/pages/personal/components/MyCourse/zxxx-zy.vue"),
        },
        {
          path: "course-zxxx-zycreate/:id",
          name: "course-zxxx-zycreate",
          component: () =>
            import("~/pages/personal/components/MyCourse/zxxx-zycreate.vue"),
        },
        {
          path: "course-kczy",
          name: "course-kczy",
          title: "课程资源",
          component: () =>
            import("~/pages/personal/components/MyCourse/kczy.vue"),
        },
        {
          path: "course-kczy-create",
          name: "course-kczy-create",
          title: "创建课程资源",
          component: () =>
            import("~/pages/personal/components/MyCourse/kczy-create.vue"),
        },
        {
          path: "course-kczy-zy/:id",
          name: "course-kczy-zy",
          title: "课程资源-资源",
          component: () =>
            import("~/pages/personal/components/MyCourse/kczy-zy.vue"),
        },
        {
          path: "course-kczy-zycreate",
          name: "course-kczy-zycreate",
          title: "课程资源-资源创建",
          component: () =>
            import("~/pages/personal/components/MyCourse/kczy-zycreate.vue"),
        },
        {
          path: "participate",
          name: "participate",
          title: "我参与的组",
          component: () =>
            import("~/pages/personal/components/Participate/index.vue"),
        },
        {
          path: "wxydz_add",
          name: "wxydz_add",
          component: () =>
            import("~/pages/personal/components/Participate/wxydz_add.vue"),
        },
        {
          path: "collection",
          name: "collection",
          title: "赞与收藏",
          component: () =>
            import("~/pages/personal/components/Collection/index.vue"),
        },
        {
          path: "attention",
          name: "attention",
          title: "我关注的人",
          component: () =>
            import("~/pages/personal/components/Attention/index.vue"),
        },
        {
          path: "homework",
          children: [
            {
              path: "",
              name: "homework",
              title: "作业",
              component: () =>
                import("~/pages/personal/components/Homework/index.vue"),
            },
            {
              path: "ssys",
              name: "personal_homework_ssys",
              redirect: {
                name: "personal_homework_ssys_cjzy",
              },
              children: [
                {
                  path: "cjzy",
                  children: [
                    {
                      path: "",
                      name: "personal_homework_ssys_cjzy",
                      component: () =>
                        import(
                          "~/pages/personal/components/Homework/ssys/cjzy/index.vue"
                        ),
                    },
                    {
                      path: "edit/:id",
                      name: "personal_homework_ssys_cjzy_edit",
                      component: () =>
                        import(
                          "~/pages/personal/components/Homework/ssys/cjzy/edit.vue"
                        ),
                      props: true,
                    },
                  ],
                },
                {
                  path: "xszy",
                  children: [
                    {
                      path: "",
                      name: "personal_homework_ssys_xszy",
                      component: () =>
                        import(
                          "~/pages/personal/components/Homework/ssys/xszy/index.vue"
                        ),
                    },
                    {
                      path: "list/:pid",
                      // name: 'personal_homework_ssys_xszy_list',
                      // component: () => import("~/pages/personal/components/Homework/ssys/xszy/list.vue"),
                      // props: true,
                      props: true,
                      children: [
                        {
                          path: "",
                          name: "personal_homework_ssys_xszy_list",
                          component: () =>
                            import(
                              "~/pages/personal/components/Homework/ssys/xszy/list.vue"
                            ),
                          props: true,
                        },
                        {
                          path: "up",
                          name: "personal_homework_ssys_xszy_up",
                          component: () =>
                            import(
                              "~/pages/personal/components/Homework/ssys/xszy/up.vue"
                            ),
                          props: true,
                        },
                      ],
                    },
                    {
                      path: "detail/:id",
                      name: "personal_homework_ssys_xszy_detail",
                      component: () =>
                        import(
                          "~/pages/personal/components/Homework/ssys/xszy/detail.vue"
                        ),
                      props: true,
                    },
                    {
                      path: "edit/:id",
                      name: "personal_homework_ssys_xszy_edit",
                      component: () =>
                        import(
                          "~/pages/personal/components/Homework/ssys/xszy/edit.vue"
                        ),
                      props: true,
                    },
                  ],
                },
              ],
            },
            {
              path: "wlzb",
              children: [
                {
                  path: "wlzb_workTab/:workType",
                  name: "personal_homework_wlzb",
                  component: () =>
                    import(
                      "~/pages/personal/components/Homework/live/index.vue"
                    ),
                },
                {
                  path: "wlzb_work/:workType",
                  name: "personal_homework_wlzb_work",
                  component: () =>
                    import(
                      "~/pages/personal/components/Homework/live/work.vue"
                    ),
                },
                {
                  path: "wlzb_worklist/:workType/:id",
                  name: "personal_homework_wlzb_worklist",
                  component: () =>
                    import(
                      "~/pages/personal/components/Homework/live/worklist.vue"
                    ),
                },
                {
                  path: "wlzb_workdetail/:workType/:id",
                  name: "personal_homework_wlzb_workdetail",
                  component: () =>
                    import(
                      "~/pages/personal/components/Homework/live/workdetail.vue"
                    ),
                },
                {
                  path: "kczy_worklist/:workType/:id",
                  name: "personal_homework_kczy_worklist",
                  component: () =>
                    import(
                      "~/pages/personal/components/Homework/live/zyWorkList.vue"
                    ),
                },
              ],
            },
          ],
        },
        {
          path: "mutualRecord",
          name: "mutualRecord",
          title: "互评记录",
          component: () =>
            import("~/pages/personal/components/MutualRecord/index.vue"),
        },
        {
          path: "wlzb",
          children: [
            {
              path: "",
              name: "personal_create_wlzb",
              component: () =>
                import("~/pages/personal/components/MyCourse/wlzb/index.vue"),
            },
            {
              path: "add",
              name: "personal_create_wlzb_add",
              component: () =>
                import("~/pages/personal/components/MyCourse/wlzb/edit.vue"),
            },
            {
              path: "edit/:id",
              name: "personal_create_wlzb_edit",
              props: true,
              component: () =>
                import("~/pages/personal/components/MyCourse/wlzb/edit.vue"),
            },
            {
              path: "kcdg/:id",
              children: [
                {
                  path: "",
                  name: "personal_create_wlzb_kcdg",
                  props: true,
                  component: () =>
                    import(
                      "~/pages/personal/components/MyCourse/wlzb/kcdg.vue"
                    ),
                },
                {
                  path: "add",
                  name: "personal_create_wlzb_kcdg_add",
                  props: true,
                  component: () =>
                    import(
                      "~/pages/personal/components/MyCourse/wlzb/kcdg_edit.vue"
                    ),
                },
                {
                  path: "edit/:bid",
                  name: "personal_create_wlzb_kcdg_edit",
                  props: true,
                  component: () =>
                    import(
                      "~/pages/personal/components/MyCourse/wlzb/kcdg_edit.vue"
                    ),
                },
              ],
            },
          ],
        },
        {
          path: "ztzb",
          children: [
            {
              path: "",
              name: "personal_create_ztzb",
              component: () =>
                import("~/pages/personal/components/MyCourse/ztzb.vue"),
            },
            {
              path: "add",
              name: "personal_create_ztzb_add",
              component: () =>
                import("~/pages/personal/components/MyCourse/ztzb-create.vue"),
            },
            {
              path: "edit/:id",
              name: "personal_create_ztzb_edit",
              props: true,
              component: () =>
                import("~/pages/personal/components/MyCourse/ztzb-create.vue"),
            },
          ],
        },
        {
          path: "credits",
          name: "credits",
          title: "我的积分",
          component: () =>
            import("~/pages/personal/components/Credits/index.vue"),
        },
        {
          path: "masterTeacher",
          name: "masterTeacher",
          title: "申请成为名师",
          component: () =>
            import("~/pages/personal/components/MasterTeacher/index.vue"),
        },
        {
          path: "yk",
          title: "约课",
          children: [
            {
              path: "",
              name: "personal_yk",
              props: true,
              component: () =>
                import("~/pages/personal/components/yk/index.vue"),
            },
            {
              path: "add",
              name: "personal_yk_add",
              props: true,
              component: () =>
                import("~/pages/personal/components/yk/edit.vue"),
            },
            {
              path: "edit/:id",
              name: "personal_yk_edit",
              props: true,
              component: () =>
                import("~/pages/personal/components/yk/edit.vue"),
            },
          ],
        },
        {
          path: "sjsb",
          title: "数据上报",
          children: [
            {
              path: "",
              name: "personal_sjsb",
              props: true,
              component: () =>
                import("~/pages/personal/components/sjsb/index.vue"),
            },
            {
              path: "add",
              name: "personal_sjsb_add",
              props: true,
              component: () =>
                import("~/pages/personal/components/sjsb/edit.vue"),
            },
            {
              path: "edit/:id",
              name: "personal_sjsb_edit",
              props: true,
              component: () =>
                import("~/pages/personal/components/sjsb/edit.vue"),
            },
          ],
        },
      ],
    },
    {
      path: "/personal/components/hz",
      name: "personal_components_hz",
      component: () => import("~/pages/personal/components/hz/index.vue"),
    },
    {
      path: "/personal/components/sz/:id",
      name: "personal_components_sz",
      component: () => import("~/pages/personal/components/sz/index.vue"),
    },
    {
      path: "/personal/components/sz/modifyPwd",
      name: "personal_components_sz_modifyPwd",
      component: () =>
        import("~/pages/personal/components/sz/modifyPwd/index.vue"),
    },
    {
      path: "/personal/components/grzxlb",
      name: "personal_components_grzxlb",
      component: () => import("~/pages/personal/components/grzxlb/index.vue"),
    },
    {
      path: "/personal/setting/:id",
      name: "personal_setting",
      component: () => import("~/pages/personal/components/main/setting.vue"),
    },

    {
      path: "/personalStudent",
      name: "personalStudent",
      title: "个人中心",
      component: () => import("~/pages/personal/index.vue"),
      redirect: "/personalStudent/xs-track",
      children: [
        {
          path: "xs-track",
          name: "xs-track",
          title: "我的足迹",
          component: () =>
            import("~/pages/personalStudent/components/xs-track/index.vue"),
        },
        {
          path: "xs-attention",
          name: "xs-attention",
          title: "我关注的人",
          component: () =>
            import("~/pages/personalStudent/components/xs-attention/index.vue"),
        },
        {
          path: "xs-credits",
          name: "xs-credits",
          title: "我的积分",
          component: () =>
            import("~/pages/personalStudent/components/xs-credits/index.vue"),
        },
        {
          path: "xs-homework",
          name: "xs-homework",
          title: "我的作业",
          component: () =>
            import("~/pages/personalStudent/components/xs-homework/index.vue"),
        },
        {
          path: "wlzb/xszy",
          name: "wlzb_xszy",
          title: "作业列表",
          component: () =>
            import(
              "~/pages/personalStudent/components/xs-homework/wlzb/xszy.vue"
            ),
        },
        {
          path: "kczy/xszy",
          name: "kczy_xszy",
          title: "作业列表",
          component: () =>
            import(
              "~/pages/personalStudent/components/xs-homework/kczy/xszy.vue"
            ),
        },

        {
          path: "xs_homework/wlzb/:id",
          name: "xs_homework_wlzb",
          title: "作业详情",
          component: () =>
            import(
              "~/pages/personalStudent/components/xs-homework/wlzb/zyxq.vue"
            ),
        },
        {
          path: "xs_homework/kczy/:id",
          name: "xs_homework_kczy",
          title: "作业详情",
          component: () =>
            import(
              "~/pages/personalStudent/components/xs-homework/kczy/zyxq.vue"
            ),
        },
      ],
    },
  ],
});

export default router;

router.beforeEach((to, from, next) => {
  if ((to.path !== "/" && to.path !== "/home") && !user) {
    ElMessage.info("请先返回首页登录");
    next({ path: "/home" });
  } else {
    next();
  }
});
