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

import java.util.Date;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.zkoss.util.resource.Labels;
import org.zkoss.zhtml.Messagebox;
import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.Executions;
import org.zkoss.zk.ui.event.Event;
import org.zkoss.zul.Button;
import org.zkoss.zul.Datebox;

import com.rjconsultores.ventaboletos.web.utilerias.MyGenericForwardComposer;

/**
 *
 * @author rodrigo
 */
@Controller("editarDataEdicaoCorridaController")
@Scope("prototype")
public class EditarDataEdicaoCorridaController extends MyGenericForwardComposer {


	private Button btnApagar;
	private Datebox fecInicio;
	private Datebox fecFinal;
	private static final Logger log = LogManager.getLogger(EditarDataEdicaoCorridaController.class);


	public Button getBtnApagar() {
		return btnApagar;
	}

	public void setBtnApagar(Button btnApagar) {
		this.btnApagar = btnApagar;
	}

	public Datebox getFecInicio() {
		return fecInicio;
	}

	public void setFecInicio(Datebox fecInicio) {
		this.fecInicio = fecInicio;
	}

	public Datebox getFecFinal() {
		return fecFinal;
	}

	public void setFecFinal(Datebox fecFinal) {
		this.fecFinal = fecFinal;
	}


	@Override
	public void doAfterCompose(Component comp) throws Exception {
		super.doAfterCompose(comp);
		fecInicio.setValue((Date) Executions.getCurrent().getArg().get("dataInicial"));
		fecFinal.setValue((Date) Executions.getCurrent().getArg().get("dataFinal"));
		

		fecInicio.focus();
	}

	@SuppressWarnings("unchecked")
	public void onClick$btnSalvar(Event ev) throws InterruptedException {
		Date inicio = fecInicio.getValue();
		Date fim = fecFinal.getValue();

		if (!fim.before(inicio)) {
			Executions.getCurrent().getArg().clear();
			Executions.getCurrent().getArg().put("dataInicial", fecInicio.getValue());
			Executions.getCurrent().getArg().put("dataFinal", fecFinal.getValue());
			
		} else {
			Messagebox.show(
					Labels.getLabel("editarVigenciaTarifaController.MSG.FimMenorInicio"),
					Labels.getLabel("editarVigenciaTarifaController.window.title"),
					Messagebox.OK, Messagebox.EXCLAMATION);
		}
	}

	
}
