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

/**
 * @category composables/layout/Menus
 * @class ConfigurationMenu
 * Classe pour la construction du Menu Paramètres
 */
class ParametersMenu extends BaseMenu implements Menu {
  private $ability: Ability;
  private $store: AnyStore;

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

  /**
   * Construit le menu Header Configuration ou null si aucune page accessible
   * @return {ItemMenu | null}
   */
  getMenus (): ItemsMenu | null {
    const children: ItemsMenu = []

    if (this.$ability.can('display', 'parameters_page')) {
      children.push(this.constructMenu('general_params', {name: 'fa-cogs'},`/parameters`, false))
    }
    if (this.$ability.can('display', 'parameters_communication_page')) {
      children.push(this.constructMenu('communication_params', {name: 'fa-comments'},`/parameters/communication`, false))
    }
    if (this.$ability.can('display', 'parameters_student_page')) {
      children.push(this.constructMenu('students_params', {name: 'fa-users'},`/parameters/student`, false))
    }
    if (this.$ability.can('display', 'parameters_education_page')) {
      children.push(this.constructMenu('education_params', {name: 'fa-graduation-cap'},`/parameters/education`, false))
    }
    if (this.$ability.can('display', 'parameters_bills_page')) {
      children.push(this.constructMenu('bills_params', {name: 'fa-euro-sign'},`/parameters/billing`, false))
    }
    if (this.$ability.can('display', 'parameters_secure_page')) {
      children.push(this.constructMenu('secure_params', {name: 'fa-lock'},`/parameters/secure`, false))
    }

    if (children.length > 0) {
      return children
    } else {
      return null
    }
  }
}

export const getParametersMenu = ($config: NuxtConfig, $ability: Ability, $store: AnyStore) => new ParametersMenu($config, $ability, $store).getMenus()
