/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.rjconsultores.ventaboletos.web.utilerias.render;

import com.rjconsultores.ventaboletos.entidad.RutaCombinacion;
import com.rjconsultores.ventaboletos.entidad.Via;
import com.rjconsultores.ventaboletos.service.ViaService;
import com.rjconsultores.ventaboletos.web.utilerias.MyGenericForwardComposer;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.zkoss.zk.ui.event.Event;
import org.zkoss.zk.ui.event.EventListener;
import org.zkoss.zul.Combobox;
import org.zkoss.zul.Comboitem;
import org.zkoss.zul.ListModelList;
import org.zkoss.zul.Listcell;
import org.zkoss.zul.Listitem;
import org.zkoss.zul.ListitemRenderer;
import org.zkoss.zul.Radio;
import org.zkoss.zul.Radiogroup;

/**
 * 
 * @author Rafius
 */
@Scope("prototype")
public class RenderCatalogoDeRutasCombinacion extends MyGenericForwardComposer implements ListitemRenderer {

	private static final long serialVersionUID = 1L;
	@Autowired
	private ViaService viaService;

	@Override
	public void render(Listitem lstm, Object o) throws Exception {
		RutaCombinacion rutaCombinacion = (RutaCombinacion) o;

		// Listcell lc = new Listcell((rutaCombinacion.getIndventa() ==
		// Boolean.TRUE) ? "Si" : "No");
		Listcell lc = new Listcell();
		// <radiogroup Id="radioGroup" >
		// <radio value="si" id="si"
		// label="${c:l('editarCatalogoDeRutaController.RadSi.value')}"
		// checked="@{rutaCombinacionList.ventaSi}"/>
		// <radio value="no" id="no"
		// label="${c:l('editarCatalogoDeRutaController.RadNo.value')}"
		// checked="@{rutaCombinacionList.ventaNo}"/>
		// </radiogroup>
		final Radiogroup rg = new Radiogroup();
		// rc.setId("radioGroup2");
		Radio r1 = new Radio();
		r1.setValue("si");
		r1.setLabel("Si");

		// r1.setId("si");
		Radio r2 = new Radio();
		r2.setValue("no");
		r2.setLabel("No");
		// r2.setId("no");
		r1.setParent(rg);
		r2.setParent(rg);
		if (rutaCombinacion.getIndventa() == Boolean.TRUE) {
			r1.setChecked(true);
		} else {
			r2.setChecked(true);
		}
		rg.addEventListener("onClick", new EventListener() {

			@Override
			public void onEvent(Event event) throws Exception {
				rg.getSelectedItem();
			}
		});
		lc.appendChild(rg);
		lc.setParent(lstm);

		lc = new Listcell(rutaCombinacion.getTramo().getDesctramo());
		lc.setParent(lstm);

		lc = new Listcell(rutaCombinacion.getTramo().getVia().getNombvia());
		lc.setParent(lstm);

		lc = new Listcell();
		Combobox combo = new Combobox();
		combo.setMold("rounded");
		combo.setWidth("100%");

		viaService.obtenerTodos();
		List<Via> lsVia = viaService.obtenerTodos();
		combo.setModel(new ListModelList(lsVia));
		combo.setSelectedItem(new Comboitem(rutaCombinacion.getTramo().getVia().getNombvia()));

		lc.appendChild(combo);
		lc.setParent(lstm);

		lstm.setAttribute("data", rutaCombinacion);
	}

}
