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

/**
 * Menu : Liste des sites internet de la structure et de ses structures parentes
 */
export default class WebsiteListMenuBuilder extends AbstractMenuBuilder {
  static readonly menuName = "WebsiteList"

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

    if (this.organizationProfile.website) {
      const url = this.organizationProfile.website + '/typo3'
      children.push(this.createItem(this.organizationProfile.name as string, undefined, url, MENU_LINK_TYPE.EXTERNAL))
    }
    _.each(this.organizationProfile.parents, (parent:any) => {
      if(parent.id != this.runtimeConfig.OPENTALENT_MANAGER_ID){
        children.push(this.createItem(parent.name, undefined, parent.website, MENU_LINK_TYPE.EXTERNAL))
      }
    })

    if (children.length > 0) {
      return this.createGroup('websiteList', {name: 'fas fa-globe-americas'},  children)
    }

    return null
  }
}
