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 EquipmentMenu
 * Classe pour la construction du Menu Matériel
 */
class EquipmentMenu 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 Equipement ou null si aucune page accessible
   * @return {ItemMenu | null}
   */
  getMenu (): ItemMenu | null {
    if (this.$ability.can('display', 'equipment_page')) {
      return this.constructMenu('equipment', 'fa-cube', '/equipment/list/', true)
    }
    return null
  }
}

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