package com.rjconsultores.ventaboletos.web.utilerias.render;

import java.text.SimpleDateFormat;

import org.zkoss.zk.ui.event.Event;
import org.zkoss.zk.ui.event.EventListener;
import org.zkoss.zul.Button;
import org.zkoss.zul.Listcell;
import org.zkoss.zul.Listitem;
import org.zkoss.zul.ListitemRenderer;

import com.rjconsultores.ventaboletos.entidad.Corrida;
import com.rjconsultores.ventaboletos.web.utilerias.MyListbox;

public class RenderCorridaOrigemDestino implements ListitemRenderer {

	private SimpleDateFormat sdf = new SimpleDateFormat("HH:mm");

	public void render(Listitem lstm, Object o) throws Exception {
		Corrida corrida = (Corrida) o;

		Listcell lc = new Listcell(corrida.getId().getCorridaId().toString());
		lc.setParent(lstm);

		lc = new Listcell(corrida.getRuta().getRutaId().toString());
		lc.setParent(lstm);

		lc = new Listcell(corrida.getRuta().getDescruta());
		lc.setParent(lstm);

		Button btn = new Button();

		lc = new Listcell();
		lc.setParent(lstm);

		btn.setWidth("16");
		btn.setHeight("16");
		btn.setImage("/gui/img/remove.png");

		btn.addEventListener("onClick", new EventListener() {
			@Override
			public void onEvent(Event event) throws Exception {
				MyListbox listBox = (MyListbox) event.getTarget().getParent().getParent().getParent();
				Listitem listItem = (Listitem) event.getTarget().getParent().getParent();
				listBox.removeItem((Corrida) listItem.getAttribute("data"));
			}
		});

		lc.appendChild(btn);

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

}