import type { RouteLocationNormalized } from 'vue-router'

export function getRouteRequiredPermissions(
  route: RouteLocationNormalized,
): string[] {
  for (const record of [...route.matched].reverse()) {
    if (typeof record.meta.permission === 'string') {
      return [record.meta.permission]
    }

    if (Array.isArray(record.meta.permissions) && record.meta.permissions.length) {
      return record.meta.permissions
    }
  }

  return []
}
