package de.ivu.elect.presentation.menu;

import java.util.List;

import javax.annotation.Nullable;

import org.apache.commons.lang3.StringUtils;

import de.ivu.elect.jee.faces.FacesContextUtil;

public abstract class AbstractSchrittMenuItem extends AbstractMenuItemEntry {

  private static final long serialVersionUID = 1L;

  @Override
  protected boolean isAjax() {
    return StringUtils.isNotBlank(getDialogName());
  }

  @Override
  public String doAction() {
    if (StringUtils.isNotBlank(getDialogName())) {
      return null; // nichts machen
    }

    return doActionInternal();
  }

  public void doActionDialog(){
    FacesContextUtil.redirectToView(this.buildRedirectForTargetViewId(doActionInternal()));
  }

  public String doActionInternal() {
    throw new UnsupportedOperationException("Implement ME: " + getClass());
  }

  @Nullable
  @Override
  public String getTargetViewId() {
    return null; // action ausführen
  }

  @Override
  protected List<String> getAdditionalTopicViewIds() {
    return super.getAdditionalTopicViewIds();
  }

  @Override
  public boolean isTopicActive() {
    return isTopicActiveInternal();
  }

  protected abstract boolean isTopicActiveInternal();

  @Override
  public String getStyleClass() {
    if (!isDisabled() && !isTopicActive()) {
      if (isBefore()) {
        return "schritt-zuvor";
      }
    }
    return super.getStyleClass();
  }

  protected boolean isBefore() {
    return false;
  }

}
