import AbstractMenuBuilder from '~/services/layout/menuBuilder/abstractMenuBuilder'
import {MenuGroup, MenuItem, MenuItems} from "~/types/layout";
import {MENU_LINK_TYPE} from "~/types/enum/layout";

/**
 * Menu Statistiques
 */
export default class StatsMenuBuilder extends AbstractMenuBuilder {
  static readonly menuName = "Stats"

  /**
   * Construit le menu Statistique et Dons ou null si aucune page accessible
   */
  build(): MenuItem | MenuGroup | null {
    const children: MenuItems = []

    if (this.ability.can('display', 'report_activity_page')) {
      children.push(this.createItem('report_activity', {name: 'fas fa-chart-bar'}, '/report_activity', MENU_LINK_TYPE.V1))
    }

    if (this.ability.can('display', 'education_quotas_page')) {
      children.push(this.createItem('educations_quotas_by_education', {name: 'fas fa-user-circle'}, '/educations_quotas_by_education_year/list/', MENU_LINK_TYPE.V1))
    }

    if (this.ability.can('display', 'fede_stats_page')) {
      children.push(this.createItem('fede_stats', {name: 'fas fa-chart-bar'}, '/statistic/membersfedeonly', MENU_LINK_TYPE.V1))
    }

    if (this.ability.can('display', 'structure_stats_page')) {
      children.push(this.createItem('structure_stats', {name: 'fas fa-chart-bar'}, '/statistic/membersfedeassos', MENU_LINK_TYPE.V1))
    }

    if (children.length > 1) {
      // Plusieurs éléments, on retourne un groupe
      return this.createGroup('stats', {name: 'fas fa-chart-bar'}, children)
    }
    else if (children.length === 1) {
      // Un seul élément, on retourne cet élément seul
      return children[0]
    }

    return null
  }
}
