/*
 * Licensed Materials - Property of Perforce Software, Inc. 
 * © Copyright Perforce Software, Inc. 2014, 2021 
 * © Copyright IBM Corp. 2009, 2014
 * © Copyright ILOG 1996, 2009
 * All Rights Reserved.
 *
 * Note to U.S. Government Users Restricted Rights:
 * The Software and Documentation were developed at private expense and
 * are "Commercial Items" as that term is defined at 48 CFR 2.101,
 * consisting of "Commercial Computer Software" and
 * "Commercial Computer Software Documentation", as such terms are
 * used in 48 CFR 12.212 or 48 CFR 227.7202-1 through 227.7202-4,
 * as applicable.
 */
package thinstock.faces.renderer;

import java.io.IOException;
import java.io.Writer;

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

import ilog.views.chart.faces.dhtml.component.IlvChartDHTMLView;
import ilog.views.chart.faces.dhtml.renderkit.IlvChartRenderer;
import ilog.views.faces.dhtml.renderkit.IlvDHTMLResponseWriter;
import ilog.views.faces.dhtml.renderkit.IlvScriptDescriptor;
import ilog.views.faces.dhtml.renderkit.IlvScriptManager;
import ilog.views.util.IlvLocaleUtil;

public class MainChartViewRenderer extends IlvChartRenderer {

  public static IlvScriptDescriptor scriptDescriptor = new IlvScriptDescriptor("mainChart",
      IlvChartRenderer.scriptDescriptor) {

    Override
    public void addScriptsToLoad(IlvScriptManager scriptManager, Writer writer) {
      scriptManager.addLocaleScript(IlvLocaleUtil.getCurrentLocale(), "/data/MainChartViewProxy-messages.js");
      scriptManager.addScript("/data/MainChartViewProxy.js");
    }
  };

  Override
  public IlvScriptDescriptor getScriptDescriptor() {
    return scriptDescriptor;
  }

  public static String getRendererType() {
    return MainChartViewRenderer.class.getName();
  }

  Override
  protected void emitJSCreation(FacesContext facesContext, UIComponent component) throws IOException {

    IlvDHTMLResponseWriter writer = new IlvDHTMLResponseWriter(facesContext, component);
    IlvChartDHTMLView cv = (IlvChartDHTMLView) component;
    String[] params = { getReferenceNodeRef(facesContext, component), component.getAttributes().get(WIDTH).toString(),
        component.getAttributes().get(HEIGHT).toString(), (cv.getClientState() == null ? "" : cv.getClientState()) };

    writer.writeJSProxyCreation("MainChartViewProxy", params);
  }

}