/**
 * 后台页鉴权守卫：未登录或无员工角色则回我的页。
 */
import { useAuth } from '@/composables/useAuth'
import { useAppMode } from '@/composables/useAppMode'

export function useAdminGuard() {
  const { isAuthenticated } = useAuth()
  const { canEnterAdmin } = useAppMode()

  function guardAdmin(): boolean {
    if (!isAuthenticated() || !canEnterAdmin.value) {
      uni.reLaunch({ url: '/pages/mine/index' })
      return false
    }
    return true
  }

  return { guardAdmin, isAuthenticated, canEnterAdmin }
}
