// createRouter：创建router实例对象
// createWebHistory：创建history模式的路由

import { createRouter, createWebHashHistory } from 'vue-router'
import Layout from '@/views/Layout/index.vue'
import Home from '@/views/Home/index.vue'

import { useTenantStore } from '@/stores/tenantStore'

const router = createRouter({
  history: createWebHashHistory(import.meta.env.BASE_URL),
  // path和component对应关系的位置
  routes: [
    {
      path: '/login',
      component: () => import('@/views/Login/index.vue')
    },
    {
      path: '/',
      component: Layout,
      children: [
        {
          path: '',
          component: Home
        },
        {
          path: 'news',
          component: () => import('@/views/News/index.vue')
        },
        {
          path: 'news/:id',
          component: () => import('@/views/NewsDetail/index.vue')
        },
        {
          path: 'newDetail/:id',
          component: () => import('@/views/NewsDetail/index.vue')
        },
        {
          path: 'textBook',
          component: () => import('@/views/TextBook/index.vue')
        },
        {
          path: 'textBookDetail',
          component: () => import('@/views/TextbookDetail/index.vue')
        },
        {
          path: 'subject',
          component: () => import('@/views/CatalogResource/index.vue')
        },
        {
          path: 'subSubject',
          component: () => import('@/views/SubCatalogResource/index.vue')
        },
        {
          path: 'subjectDetail',
          component: () => import('@/views/CatalogResourceDetail/index.vue')
        },
        {
          path: 'teacher',
          component: () => import('@/views/Teacher/index.vue')
        },
        {
          path: 'teacher/:id',
          component: () => import('@/views/TeacherDetail/index.vue')
        }
      ]
    }
  ],
  // 路由滚动行为定制
  scrollBehavior() {
    return {
      top: 0
    }
  }
})

router.beforeEach((to, from) => {
  useTenantStore().getTenantInfo()

  return true
})

export default router
