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

import de.ivu.elect.jee.presentation.menu.IVUDefaultMenuItem;
import de.ivu.elect.presentation.menu.AbstractMenuItemEntry;
import de.ivu.elect.presentation.security.AbstractGebietSecurity;
import org.primefaces.model.menu.MenuElement;

import java.util.Collections;
import java.util.List;

public class KalenderMainMenuEntry extends AbstractMenuItemEntry {

  private static final long serialVersionUID = 1L;

  private static final String ICON_BADGE_COUNTER_NAME = "ui-icon-badge-counter-system-log";

  private static final long DUMMY_ANZAHL_DER_KALENDEREINTRAEGE = 3L;

  public KalenderMainMenuEntry() {
    super();
  }

  @Override
  public MenuElement buildComponent() {
    IVUDefaultMenuItem defaultMenuItem = (IVUDefaultMenuItem) super.buildComponent();
    defaultMenuItem.setOnclick(getOnclick());
    defaultMenuItem.setCommand(null);
    return defaultMenuItem;
  }

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

  @Override
  public boolean isRendered() {
    return isLoggedIn();
  }

  @Override
  public boolean isDisabledInternal() {
    return false;
  }

  public String getOnclick() {
    return "PF('sidebar2').show()";
  }

  @Override
  public String doAction() {
    return NO_ACTION_NO_REDIRECT;
  }

  @Override
  protected boolean isShowBlockUi() {
    return false; // wird in neuem Browserfenster geöffnet, daher kein BlockUi
  }

  @Override
  protected boolean isAjax() {
    return true;
  }

  @Override
  public String getTargetViewId() {
    return null;
  }

  @Override
  public String getLabelKey() {
    return "";
  }

  @Override
  public String getTitle() {
    return "Wahlkalender";
  }

  @Override
  protected String getLabel() {
    // NOTE, dass nur das Icon angezeigt werden soll!
    return "";
  }

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

  @Override
  public String getStyleClass() {
    if (DUMMY_ANZAHL_DER_KALENDEREINTRAEGE > 0) {
      return super.getStyleClass() + " ui-icon-badge " + ICON_BADGE_COUNTER_NAME;
    }
    return super.getStyleClass();
  }

  @Override
  public String getStyle() {
    long anzahlDerKalendereintraege = DUMMY_ANZAHL_DER_KALENDEREINTRAEGE;
    if (anzahlDerKalendereintraege > 0) {
      return super.getStyle() + " counter-reset: " + ICON_BADGE_COUNTER_NAME + " " + Math.min(anzahlDerKalendereintraege, 99) + ";";
    }

    return super.getStyle();
  }

  @Override
  protected List<String> getAdditionalTopicViewIds() {
    return Collections.singletonList("");
  }
}
