package de.ivu.elect.presentation.wahl.menu;

import java.util.ArrayList;
import java.util.List;

import javax.inject.Inject;
import javax.inject.Named;

import de.ivu.elect.jee.presentation.menu.AbstractSubMenuEntry;
import de.ivu.elect.jee.presentation.menu.MenuEntry;
import de.ivu.elect.jee.presentation.menu.SeparatorMenuEntry;
import de.ivu.elect.presentation.menu.AbstractMenuItemEntry;
import de.ivu.elect.presentation.menu.MainMenu;
import de.ivu.elect.presentation.menu.MainServiceMenu;
import de.ivu.elect.presentation.menu.StartViewMenuItemEntry;
import de.ivu.elect.presentation.praesentation.menu.PraesentationMainMenuEntry;
import de.ivu.elect.presentation.ui.AbstractPageMenuModelBuilder;

@Named(NlWahlprozessPageMenu.COMPONENT_NAME)
public class NlWahlprozessPageMenu extends AbstractPageMenuModelBuilder {

  private static final long serialVersionUID = 1L;

  public static final String COMPONENT_NAME = "nlWahlprozessPageMenu";

  @Inject
  private transient MainMenu mainMenu;

  @Inject
  private transient MainServiceMenu mainServiceMenu;

  @Inject
  private transient SeparatorMenuEntry separatorMenuEntry;

  @Override
  public List<MenuEntry> getMenuEntriesSorted() {

    List<MenuEntry> result = new ArrayList<>();

    for (MenuEntry menuEntry : mainMenu.getMenuEntriesSorted()) {

      if (menuEntry instanceof AbstractSubMenuEntry) {
        if (menuEntry instanceof PraesentationMainMenuEntry) {
          // skip - stört nur
        } else {
          add(result, (AbstractSubMenuEntry) menuEntry);
          result.add(separatorMenuEntry);
        }
        // Prozess nicht explizit mit aufnehmen
//      } else if (menuEntry instanceof AbstractMenuItemEntry) {
//        if (menuEntry instanceof StartViewMenuItemEntry) {
//          // ignorieren
//        } else if (menuEntry.isRendered()) {
//          result.add(menuEntry);
//        }
      }
    }
//    for (MenuEntry menuEntry : mainServiceMenu.getMenuEntriesSorted()) {
//      if (menuEntry instanceof AbstractSubMenuEntry) {
//        add(result, (AbstractSubMenuEntry) menuEntry);
//        result.add(separatorMenuEntry);
//      }
//    }

    return result;
  }

  private void add(List<MenuEntry> result, AbstractSubMenuEntry menuEntry) {
    for (MenuEntry subMenuEntry : menuEntry.getSubMenuEntries()) {
      if (subMenuEntry.isRendered()) {
        result.add(subMenuEntry);
      }
    }
  }

}
