
package de.ivu.elect.jee.presentation.dynamicform;

import javax.faces.convert.Converter;

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

@Deprecated // elect-technical-ckeditor einbinden, wenn verwendet
public abstract class AbstractCKEditorProperty extends AbstractProperty {

  protected static final String COMPACT_TOOLBAR_WIDTH = "722px";

  protected static final String COMPACT_TOOLBAR_CONFIG = "[" +
      "{name:'undo', items:['Undo','Redo']}," +
      "{name:'basicstyles', items:['Bold','Italic','Underline','Strike','Superscript']}," +
      "{name:'colors', items:['TextColor','BGColor']}," +
      "{name:'fontstyles', items:['FontSize']}," +
      "{name:'lists', items:['BulletedList','NumberedList','Outdent','Indent']}," +
      "{name:'inserts', items:['Link','Unlink','base64image','HorizontalRule']}," +
      "{name:'document', items:['Source']}," +
      "]";

  protected static final String COMPACT_TOOLBAR_WITH_PLACEHOLDER_WIDTH = "750px";

  protected static final String COMPACT_TOOLBAR_WITH_PLACEHOLDER_CONFIG = "[" +
      "{name:'undo', items:['Undo','Redo']}," +
      "{name:'basicstyles', items:['Bold','Italic','Underline','Strike','Superscript']}," +
      "{name:'colors', items:['TextColor','BGColor']}," +
      "{name:'fontstyles', items:['FontSize']}," +
      "{name:'lists', items:['BulletedList','NumberedList','Outdent','Indent']}," +
      "{name:'inserts', items:['CreatePlaceholder','Link','Unlink','base64image','HorizontalRule']}," +
      "{name:'document', items:['Source']}," +
      "]";

  protected static final String COMPLEX_TOOLBAR_WIDTH = "604px";

  protected static final String COMPLEX_TOOLBAR_CONFIG = "[" +
      "{name:'undo', items:['Undo','Redo']}," +
      "{name:'fontstyles', items:['Font','FontSize']}," +
      "{name:'alignment', items:['JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock']}," +
      "{name:'indents', items:['Outdent','Indent']}," +
      "{name:'document', items:['Source']}," +
      "{name:'tools', items:['Maximize']}," +
      "'/'," +
      "{name:'basicstyles', items:['Bold','Italic','Underline','Strike','Subscript','Superscript']}," +
      "{name:'colors', items:['TextColor','BGColor']}," +
      "{name:'lists', items:['BulletedList','NumberedList']}," +
      "{name:'links', items:['Link','Unlink']}," +
      "{name:'inserts', items:['Image','Table','HorizontalRule','Smiley','SpecialChar']}," +
      "]";

  protected static final String COMPLEX_TOOLBAR_WITH_PLACEHOLDER_CONFIG = "[" +
      "{name:'undo', items:['Undo','Redo']}," +
      "{name:'fontstyles', items:['Font','FontSize']}," +
      "{name:'alignment', items:['JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock']}," +
      "{name:'indents', items:['Outdent','Indent']}," +
      "{name:'document', items:['Source']}," +
      "{name:'tools', items:['Maximize']}," +
      "'/'," +
      "{name:'basicstyles', items:['Bold','Italic','Underline','Strike','Subscript','Superscript']}," +
      "{name:'colors', items:['TextColor','BGColor']}," +
      "{name:'lists', items:['BulletedList','NumberedList']}," +
      "{name:'placeholder', items:['CreatePlaceholder']}," +
      "{name:'links', items:['Link','Unlink']}," +
      "{name:'inserts', items:['Image','Table','HorizontalRule','Smiley','SpecialChar']}," +
      "]";

  public AbstractCKEditorProperty() {
    super();
  }

  @Override
  public PropertyType getDefaultType() {
    return PropertyType.CKEDITOR;
  }

  @Override
  public Converter getDefaultConverter() {
    return new StringEmptyToNullConverter();
  }

  @Override
  protected boolean hasDefaultValue() {
    return notNullOrBlank(getDefaultValue());
  }

  public String getDefaultValue() {
    return null;
  }

  @Override
  public boolean hasValue() {
    return notNullOrBlank(getValue());
  }

  public abstract String getValue();

  public abstract void setValue(String value);

  public String getWidth() {
    if (isToolbarComplex()) {
      return COMPLEX_TOOLBAR_WIDTH;
    }
    if (isPlaceholderButtonEnabled()) {
      return COMPACT_TOOLBAR_WITH_PLACEHOLDER_WIDTH;
    }
    return COMPACT_TOOLBAR_WIDTH;
  }

  public String getToolbar() {
    if (isToolbarComplex()) {
      if (isPlaceholderButtonEnabled()) {
        return COMPLEX_TOOLBAR_WITH_PLACEHOLDER_CONFIG;
      }
      return COMPLEX_TOOLBAR_CONFIG;
    }
    if (isPlaceholderButtonEnabled()) {
      return COMPACT_TOOLBAR_WITH_PLACEHOLDER_CONFIG;
    }
    return COMPACT_TOOLBAR_CONFIG;
  }

  protected boolean isToolbarComplex() {
    return false;
  }

  protected boolean isPlaceholderButtonEnabled() {
    return false;
  }

  /*
   * An JavaScript array of options. Each option is a 1- or 2-item array of format [ 'Description', 'Value' ].
   * If 'Value' is missing, then the value would be assumed to be the same as the description.
   *
   * Example: [ [ 'Basketball', 'BASKETBALL' ], [ 'Hockey', 'HOCKEY' ], [ 'Football', 'FOOTBALL' ] ]
   *
   * @return JavaScript code as String
   */
  public String getPlaceholderItems() {
    return null;
  }
}
