import { Plugin } from '@nuxt/types'
import { Ability } from '@casl/ability'
import { $abilitiesUtils } from '~/services/rights/abilitiesUtils'

/**
 * Au moment de la phase D'init de Nuxt...
 * @param ctx
 */
const abilityPlugin: Plugin = (ctx) => {
  $abilitiesUtils(ctx.store, ability).setAbilities()
  // Déclare un nouvel accesseur de service via le context Nuxt
  ctx.$ability = ability
}

export default abilityPlugin
export const ability = new Ability()
