package com.navistar.acme.gwt.client.widget;

import com.smartgwt.client.types.Alignment;
import com.smartgwt.client.widgets.Canvas;
import com.smartgwt.client.widgets.Label;
import com.smartgwt.client.widgets.form.fields.StaticTextItem;
import com.smartgwt.client.widgets.layout.HLayout;
import com.smartgwt.client.widgets.layout.HStack;
import com.smartgwt.client.widgets.layout.VLayout;
import com.smartgwt.client.widgets.layout.VStack;

/**
 * @author hari_k
 * 
 */
public class BaseComponents {

  /**
   * @return the defined SmartVLayout object which extends VLayout
   */
  public SmartVLayout getSmartVLayout() {
    return new SmartVLayout();
  }

  /**
   * @return the defined SmartHLayout object which extends HLayout
   */
  public SmartHLayout getSmartHLayout() {
    return new SmartHLayout();
  }

  /**
   * @return the defined SmartHStack object which extends HStack
   */
  public SmartHStack getSmartHStack() {
    return new SmartHStack();
  }

  /**
   * @return the defined SmartVStack object which extends VStack
   */
  public SmartVStack getSmartVStack(boolean styleRequired) {
    return new SmartVStack(styleRequired);
  }

  public SmartLabel getSmartLabel(String title) {
    SmartLabel smartLabel = new SmartLabel(title);
    smartLabel.setWrap(false);
    smartLabel.setHeight100();
    smartLabel.setAlign(Alignment.LEFT);
    return smartLabel;
  }

  public SmartLabel getSmartLabel(String title, int height, int extraSpace) {
    return new SmartLabel(title, height, extraSpace);
  }

  public SmartLabel getSmartHeaderLabel(String title, int height, int extraSpace) {
    SmartLabel smartLabel = new SmartLabel(title, height, extraSpace);
    smartLabel.setStyleName("formBlockLabel");
    return smartLabel;
  }

  public SmartLabel getSmartFormHeaderLabel(String title) {
    SmartLabel smartLabel = new SmartLabel(title);
    smartLabel.setStyleName("formHeader");
    smartLabel.setHeight100();
    smartLabel.setAlign(Alignment.LEFT);
    return smartLabel;
  }

  /**
   * SmartVLayout extends VLayout
   * 
   */
  public static class SmartVLayout extends VLayout {

    public SmartVLayout() {
      setWidth100();
      setHeight100();
    }

    public void addMember(Canvas... membersToAdd) {
      for (Canvas memberToAdd : membersToAdd) {
        addMember(memberToAdd);
      }
    }
  }

  /**
   * SmartHLayout extends HLayout
   * 
   */
  public static class SmartHLayout extends HLayout {

    public SmartHLayout() {
      setWidth100();
      setHeight100();
      setStyleName("formBlock");
    }

    public void addMember(Canvas... membersToAdd) {
      for (Canvas memberToAdd : membersToAdd) {
        addMember(memberToAdd);
      }
    }
  }

  /**
   * SmartHStack extends HStack
   * 
   */
  public static class SmartHStack extends HStack {

    public SmartHStack() {
      setWidth100();
      setHeight100();
      setStyleName("formBlock");
    }

    public void addMember(Canvas... membersToAdd) {
      for (Canvas memberToAdd : membersToAdd) {
        addMember(memberToAdd);
      }
    }
  }

  /**
   * SmartVStack extends VStack
   * 
   */
  public static class SmartVStack extends VStack {

    public SmartVStack() {
      setWidth100();
      setHeight100();
    }

    public SmartVStack(boolean styleRequired) {
      setWidth100();
      setHeight100();
      if (styleRequired) {
        setStyleName("formBlock");
      }
    }

    public void addMember(Canvas... membersToAdd) {
      for (Canvas memberToAdd : membersToAdd) {
        addMember(memberToAdd);
      }
    }
  }

  /**
   * SmartLabel extends Label
   * 
   */
  public static class SmartLabel extends Label {

    public SmartLabel() {
    }

    public SmartLabel(String title) {
      setContents(title);
    }

    public SmartLabel(String title, int height, int extraSpace) {
      setContents(title);
      if (height == 100) {
        setHeight100();
      } else {
        setHeight(height);
      }
      setExtraSpace(extraSpace);
      setWrap(false);
      setAlign(Alignment.LEFT);
    }
  }

  public StaticTextItem getSmartStaticTextItem(String title) {
    return getSmartStaticTextItem(title, null);
  }

  public StaticTextItem getSmartStaticTextItem(String title, String value) {
    StaticTextItem assemblyLabel = new StaticTextItem();
    assemblyLabel.setTitle(title);
    assemblyLabel.setValue(value);
    assemblyLabel.setTitleStyle("label-bold");
    assemblyLabel.setWrap(true);
    assemblyLabel.setWrapTitle(false);
    assemblyLabel.setTitleAlign(Alignment.LEFT);

    return assemblyLabel;
  }
}
