
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 wahlSessionSelect;

  public KandidaturSearchMenuItemEntry() {
    super();
  }

  @Override
  public boolean isRendered() {
    return hasUseCasePermission(getUseCasePermission()) && isWahlMitKandidaturenSelected();
  }

  public UseCasePermission getUseCasePermission() {
    return UseCasePermission.KANDIDATUR_SEARCH;
  }

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

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

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

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

  protected Wahl getSelectedWahl() {
    return wahlSessionSelect.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();
  }
}
