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

/**
 * Menu agenda
 */
export default class AgendaMenuBuilder extends AbstractMenuBuilder {
  static readonly menuName = "Agenda"

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

    if (this.ability.can('display', 'agenda_page')) {
      children.push(this.createItem('schedule', {name: 'fas fa-calendar-alt'}, '/calendar', MENU_LINK_TYPE.V1))
    }

    if (this.ability.can('display', 'attendance_page')) {
      children.push(this.createItem('attendances', {name: 'fas fa-calendar-check'}, '/attendances/list/', MENU_LINK_TYPE.V1))
    }

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

    return null
  }
}
