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

/**
 * @category composables/layout/Menus
 * @class DonorsMenu
 * Classe pour la construction du Menu Donneurs
 */
class DonorsMenu 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 Partenariat et Dons ou null si aucune page accessible
   * @return {ItemMenu | null}
   */
  getMenu (): ItemMenu | null {
    if (this.$ability.can('display', 'donors_page')) {
      return this.constructMenu('donors', 'far fa-handshake', '/donors/list/', true)
    }
    return null
  }
}

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