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

import javax.inject.Inject;

import de.ivu.elect.business.security.UseCasePermission;
import de.ivu.elect.business.wahl.boundary.WahlSessionSelect;
import de.ivu.elect.business.wahl.entity.Wahl;
import de.ivu.elect.presentation.kandidatur.KandidaturSearchView;
import de.ivu.elect.presentation.menu.AbstractMenuItemEntry;
import de.ivu.elect.presentation.security.AbstractGebietSecurity;

public class KandidaturSearchMenuItemEntry extends AbstractMenuItemEntry {

  private static final long serialVersionUID = 1L;

  public static final String COMPONENT_NAME = "kandidaturSearchMenuItemEntry";

  @Inject
  private transient WahlSessionSelect wahlSelect;

  public KandidaturSearchMenuItemEntry() {
    super();
  }

  @Override
  public boolean isRendered() {
    return hasUseCasePermission(UseCasePermission.KANDIDATUR_SEARCH) && isWahlMitKandidaturenSelected();
  }

  @Override
  protected AbstractGebietSecurity getGebietSecurity() {
    return getEinsehenGebietSecurity();
  }

  @Override
  public boolean isDisabledInternal() {
    return !isGebietSelected();
  }

  private boolean isWahlMitKandidaturenSelected() {
    return isWahlSelected() && getSelectedWahl().isWahlMitKandidaturen();
  }

  private boolean isWahlSelected() {
    return wahlSelect.isSelected();
  }

  protected Wahl getSelectedWahl() {
    return wahlSelect.getEntity();
  }

  @Override
  public String getTargetViewId() {
    return KandidaturSearchView.VIEW_ID;
  }

  @Override
  public String getLabelKey() {
    return "kandidatur.search.menu.item.label";
  }

  @Override
  public String getIcon() {
    return getIcons().getIconSearch();
  }
}
