import DEFAULT from '@/layouts/default';
import store from '@/store';

export const LoginPage = {
  path: '/login',
  name: 'Login',
  component: () => import('@/views/login'),
};

export const EnterSys = {
  path: '/EnterSys',
  beforeEnter: (to, from, next) => {
    store
      .dispatch('user/enterSys')
      .then(() => {
        const { tab, enter, dateStamp } = to.query;
        if (enter) {
          next(`/${enter}?tab=${tab}&dateStamp=${dateStamp}`);
        } else {
          next('/');
        }
      })
      .catch(() => {
        store.dispatch('user/signOut');
        next('/login');
      });
  },
};

export const HomePage = {
  path: '/',
  component: DEFAULT,
  redirect: '/personal_question',
  meta: { title: '练习管理', icon: 'practice' },
  children: [
    // 公共题库
    {
      path: 'home',
      name: 'Home',
      component: () => import('@/views/home/public_question'),
    },
    // 个人题库
    {
      path: 'personal_question',
      name: 'Personal',
      component: () => import('@/views/home/personal_question'),
    },
    // 协作题库
    {
      path: 'collaborate_question',
      name: 'Collaborate',
      component: () => import('@/views/home/collaborate_question'),
    },
    // 回收页
    {
      path: 'recovery',
      meta: { title: '回收' },
      component: () => import('@/views/home/recovery/index.vue'),
    },
    {
      path: 'answer_data',
      component: () => import('@/views/home/recovery/AnswerData.vue'),
    },
  ],
};

export const NotFoundPage = {
  path: '*',
  name: '404',
  component: () => import('@/views/not_found/404.vue'),
};
