import type { IMenuItem } from '@/types'
import { defineStore } from 'pinia'
import { useUserStore } from '@/stores/user'

interface State {
  studentMenus: IMenuItem[]
  adminMenus: IMenuItem[]
  teacherMenus: IMenuItem[]
  expertMenus: IMenuItem[]
}

// 学生菜单
const studentMenus: IMenuItem[] = [
  {
    name: '首页',
    path: '/'
  },
  {
    name: '我的实验',
    path: '/student/lab'
  },
  {
    name: '我的大赛',
    path: '/student/contest'
  },
  {
    name: '大赛成绩查询',
    path: '/student/contest/score'
  }
]
// 教师菜单
const teacherMenus: IMenuItem[] = [
  {
    name: '首页',
    path: '/'
  },
  {
    name: '实验指导书管理',
    path: '/teacher/lab/book',
    tag: 'v1-teacher-book'
  },
  {
    name: '实验操作视频管理',
    path: '/teacher/lab/video',
    tag: 'v1-teacher-video'
  },
  {
    name: '实验讨论交流',
    path: '/teacher/lab/discuss',
    tag: 'v1-teacher-discussion'
  },
  {
    name: '实验成绩管理',
    path: '/teacher/lab/record',
    tag: 'v1-teacher-record'
  },
  {
    name: '大赛训练答疑',
    path: '/teacher/contest/discuss'
  }
]
// 专家菜单
const expertMenus: IMenuItem[] = [
  {
    name: '首页',
    path: '/'
  },
  {
    name: '训练答疑',
    path: '/teacher/contest/discuss'
  },
  {
    name: '大赛评分',
    path: '/teacher/contest/record'
  },
  {
    name: '大赛发布成绩',
    path: '/teacher/contest/score'
  },
  {
    name: '大赛成绩分析',
    path: '/teacher/contest/analyze',
    children: [
      {
        name: '赛项成绩画像',
        path: '/teacher/contest/score/analyze'
      },
      {
        name: '学生个人成绩画像',
        path: '/teacher/contest/student/analyze'
      }
    ]
  }
]
// 管理员菜单
const adminMenus: IMenuItem[] = [
  {
    name: '实验管理',
    path: '/admin/lab/experiment',
    tag: 'v1-backend-experiment'
  },
  {
    name: '赛项管理',
    path: '/admin/contest/items'
  },
  {
    name: '参赛选手管理',
    path: '/admin/contest/contestants'
  },
  {
    name: '评分专家管理',
    path: '/admin/contest/experts'
  }
]

export const useMenuStore = defineStore({
  id: 'menu',
  state: (): State => ({
    studentMenus,
    adminMenus,
    teacherMenus,
    expertMenus
  }),
  getters: {
    menus: state => {
      const userStore = useUserStore()
      if (userStore.role?.id === 6) {
        return state.expertMenus
      } else if (userStore.role?.id === 5) {
        return state.teacherMenus
      } else if (userStore.role?.id === 1) {
        return state.studentMenus
      } else {
        return state.adminMenus
      }
    }
  },
  actions: {}
})
