import { NuxtConfig } from '@nuxt/types/config'
import { Ability } from '@casl/ability'
import { ItemMenu, Menu } from '~/types/interfaces'
import BaseMenu from '~/composables/layout/Menus/baseMenu'

/**
 * @category composables/layout/Menus
 * @class MedalsMenu
 * Classe pour la construction du Menu Médailles
 */
class MedalsMenu extends BaseMenu implements Menu {
  private $ability: Ability;

  /**
   * @constructor
   * Initialisation des services issues du context
   */
  constructor ($config: NuxtConfig, $ability: Ability) {
    super($config)
    this.$ability = $ability
  }

  /**
   * Construit le menu Médails et Dons ou null si aucune page accessible
   * @return {ItemMenu | null}
   */
  getMenu (): ItemMenu | null {
    if (this.$ability.can('display', 'medals_page')) {
      return this.constructMenu('medals', 'fa-trophy', '/medals/list/', true)
    }
    return null
  }
}

export const getMedalsMenu = ($config: NuxtConfig, $ability: Ability) => new MedalsMenu($config, $ability).getMenu()
