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

/**
 * Menu Suivi pédagogique
 */
export default class EducationalMenuBuilder extends AbstractMenuBuilder {
  static readonly menuName = "Educational"

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

    if (this.ability.can('display', 'criteria_notations_page')) {
      children.push(this.createItem('criteria_notations', {name: 'fas fa-bars'}, '/criteria_notations/list/', MENU_LINK_TYPE.V1))
    }

    if (this.ability.can('display', 'education_notation_config_page')) {
      children.push(this.createItem('education_notation_configs', {name: 'fas fa-bars'},  '/education_notation_configs/list/', MENU_LINK_TYPE.V1))
    }

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

    if (this.ability.can('display', 'test_seizure_page')) {
      children.push(this.createItem('test_seizure', {name: 'fas fa-pencil-alt'}, '/education_input/list/', MENU_LINK_TYPE.V1))
    }

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

    if (this.ability.can('display', 'examen_results_page')) {
      children.push(this.createItem('examen_results', {name: 'fas fa-graduation-cap'}, '/examen_convocations/list/', MENU_LINK_TYPE.V1))
    }

    if (this.ability.can('display', 'education_by_student_validation_page')) {
      children.push(this.createItem('education_by_student_validation', {name: 'fas fa-check-square'}, '/education_by_student/list/', MENU_LINK_TYPE.V1))
    }


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

    return null
  }
}
