/**
 * 
 */
package org.richfaces.realworld.tags;

import java.io.IOException;

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.context.ResponseWriter;

import org.ajax4jsf.renderkit.AjaxCommandRendererBase;
import org.ajax4jsf.renderkit.RendererUtils.HTML;


/**
 * @author Andrey Markavtsov
 *
 */
//TODO nick - remove this
public class RealworldCommandButtonRenderer extends AjaxCommandRendererBase {
	
	@Override
	public void encodeBegin(FacesContext context, UIComponent component)
			throws IOException {
		Object id = component.getClientId(context);
		Object style = component.getAttributes().get("style");
		Object value = component.getAttributes().get("value");
		
		ResponseWriter writer = context.getResponseWriter();
		writer.startElement(HTML.DIV_ELEM, component);
			writer.writeAttribute(HTML.id_ATTRIBUTE, id, null);
			writer.writeAttribute(HTML.class_ATTRIBUTE, "realworldButton", null);
			writer.writeAttribute(HTML.style_ATTRIBUTE, style, null);
			writer.writeAttribute(HTML.onclick_ATTRIBUTE, getOnClick(context, component), null);
			
		writer.startElement(HTML.IMG_ELEMENT, component);
			writer.writeAttribute(HTML.src_ATTRIBUTE, "img/shell/button.png", null);
			writer.writeAttribute(HTML.width_ATTRIBUTE, "103", null);
			writer.writeAttribute(HTML.height_ATTRIBUTE, "28", null);
			writer.writeAttribute(HTML.alt_ATTRIBUTE, "", null);
			writer.writeAttribute(HTML.border_ATTRIBUTE, "0", null);
		writer.endElement(HTML.IMG_ELEMENT);
		
		writer.startElement(HTML.DIV_ELEM, component);
			writer.writeText(value, null);
		writer.endElement(HTML.DIV_ELEM);
		
		writer.startElement(HTML.IMG_ELEMENT, component);
			writer.writeAttribute(HTML.src_ATTRIBUTE, "img/shell/spacer.gif", null);
			writer.writeAttribute(HTML.width_ATTRIBUTE, "103", null);
			writer.writeAttribute(HTML.height_ATTRIBUTE, "28", null);
			writer.writeAttribute(HTML.alt_ATTRIBUTE, "", null);
			writer.writeAttribute(HTML.border_ATTRIBUTE, "0", null);
		writer.endElement(HTML.IMG_ELEMENT);	
		
		writer.endElement(HTML.DIV_ELEM);
	}
	
	@Override
	protected Class<? extends UIComponent> getComponentClass() {
		return org.ajax4jsf.component.UIAjaxCommandButton.class;
	}

}
