// 以下代码在build时自动移除，无需手动注释
// #ifdef DEV
// import './user/tmp'
// #endif
import type { User } from './user/index.d'
import router, { FilteredRoutesMap, asyncFilteredRoutes } from '~/router/index'

export const user = ref<User>(JSON.parse(localStorage.getItem('userInfo') ?? '{}'))

watch(
  () => user.value,
  (val) => {
    if (val === null) {
      localStorage.removeItem('userInfo')
      asyncFilteredRoutes.value.forEach((routes) => {
        router.removeRoute(routes.name!)
      })
      FilteredRoutesMap.value = null
    }
    else {
      localStorage.setItem('userInfo', JSON.stringify(val))
    }
  },
)

export function getUserRole() {
  const user_role_id = user.value.user_role_id
  if (['69', '70', '71'].includes(user_role_id))
    return 'qxgly'

  else if (['72'].includes(user_role_id))
    return 'xgly'

  else if (['73', '74', '75'].includes(user_role_id))
    return 'teacher'
}
