import AbstractMenuBuilder from '~/services/layout/menuBuilder/abstractMenuBuilder'
import {MenuGroup, MenuItem, MenuItems} from "~/types/layout";
import AccessMenuBuilder from "~/services/layout/menuBuilder/accessMenuBuilder";
import AgendaMenuBuilder from "~/services/layout/menuBuilder/agendaMenuBuilder";
import EquipmentMenuBuilder from "~/services/layout/menuBuilder/equipmentMenuBuilder";
import EducationalMenuBuilder from "~/services/layout/menuBuilder/educationalMenuBuilder";
import BillingMenuBuilder from "~/services/layout/menuBuilder/billingMenuBuilder";
import CommunicationMenuBuilder from "~/services/layout/menuBuilder/communicationMenuBuilder";
import MedalsMenuBuilder from "~/services/layout/menuBuilder/medalsMenuBuilder";
import DonorsMenuBuilder from "~/services/layout/menuBuilder/donorsMenuBuilder";
import WebsiteAdminMenuBuilder from "~/services/layout/menuBuilder/websiteAdminMenuBuilder";
import CotisationsMenuBuilder from "~/services/layout/menuBuilder/cotisationsMenuBuilder";
import StatsMenuBuilder from "~/services/layout/menuBuilder/statsMenuBuilder";
import Admin2iosMenuBuilder from "~/services/layout/menuBuilder/admin2iosMenuBuilder";

/**
 * Menu principal (ou menu lateral)
 */
export default class MainMenuBuilder extends AbstractMenuBuilder {
  static readonly menuName = "Main"

  /**
   * Construit le menu principal, ou null si aucune page accessible
   */
  build (): MenuGroup | MenuItem | null {
    const children: MenuItems = [
      this.buildSubmenu(AccessMenuBuilder),
      this.buildSubmenu(AgendaMenuBuilder),
      this.buildSubmenu(EquipmentMenuBuilder),
      this.buildSubmenu(EducationalMenuBuilder),
      this.buildSubmenu(BillingMenuBuilder),
      this.buildSubmenu(CommunicationMenuBuilder),
      this.buildSubmenu(DonorsMenuBuilder),
      this.buildSubmenu(MedalsMenuBuilder),
      this.buildSubmenu(WebsiteAdminMenuBuilder),
      this.buildSubmenu(CotisationsMenuBuilder),
      this.buildSubmenu(StatsMenuBuilder),
      this.buildSubmenu(Admin2iosMenuBuilder)
    ].filter((m: MenuItem | MenuGroup | null) => m !== null)

    if (children.length > 1) {
      // Plusieurs éléments, on retourne un groupe
      return this.createGroup('main', undefined,  children)
    } else if (children.length === 1) {
      // Un seul élément, on retourne cet élément seul
      return children[0]
    }

    return null
  }
}
