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

/**
 * Menu Répertoire
 */
export default class AccessMenuBuilder extends AbstractMenuBuilder {
  static readonly menuName = "Access"

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

    if (this.ability.can('display', 'accesses_page')) {
      // @ts-ignore
      const to = this.organizationProfile.isSchool ? '/students/list/' : '/adherent/list/'
      children.push(this.createItem('person', {name: 'fas fa-user'}, to, MENU_LINK_TYPE.V1))
    }

    if (this.ability.can('display', 'student_registration_page')) {
      children.push(this.createItem('family_view', {name: 'fas fa-users'}, '/student_registration/new', MENU_LINK_TYPE.V1))
    }

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

    if (this.ability.can('display', 'commissions_page')) {
      children.push(this.createItem('commissions', {name: 'fas fa-street-view'}, '/commissions/list/', MENU_LINK_TYPE.V1))
    }

    if (this.ability.can('display', 'network_children_page')) {
      children.push(this.createItem('network', {name: 'fas fa-sitemap'}, 'networks/list/', MENU_LINK_TYPE.V1))
    }

    if (this.ability.can('display', 'network_parents_page')) {
      children.push(this.createItem('my_network', {name: 'fas fa-sitemap'}, '/network_artist_schools/list/', MENU_LINK_TYPE.V1))
    }

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

    return null
  }
}
