package depart.frontal.taches;

import ca.ntro.app.tasks.frontend.FrontendTasks;
import depart.frontal.vues.VueA;
import depart.frontal.vues.VueB;
import depart.frontal.evenements.EvtA;
import depart.frontal.evenements.EvtB;
import depart.frontal.vues.VueRacine;
import ca.ntro.app.Ntro;

import static ca.ntro.app.tasks.frontend.FrontendTasks.*;

public class TachesB {
	
	public static void creerTaches(FrontendTasks tasks) {
		
		tasks.taskGroup("TachesB")
		
		     .waitsFor("TachesA")
		
		     .contains(subTasks -> {

				tacheB1(subTasks);

				tacheB2(subTasks);

				tacheB3(subTasks);

		     });
	}

	private static void tacheB1(FrontendTasks subTasks) {

		subTasks.task("tacheB1")
		
		        .waitsFor(window())
		      
		        .waitsFor(created(VueRacine.class))

		        .executes(inputs -> {
		    	  
		    	  var objA  = inputs.get(created(VueRacine.class));
		    	  var objB  = inputs.get(window());

		    	  objB.installRootView(objA);
		      });
	}

	private static void tacheB2(FrontendTasks subTasks) {

		subTasks.task("tacheB2")

		        .waitsFor(window())

		        .executes(inputs -> {

		    	    var objC = inputs.get(window());

		    	    objC.show();
		    	    
		        });
	}

	private static void tacheB3(FrontendTasks tasks) {

		tasks.task("tacheB3")

		     .waitsFor(created(VueRacine.class))  // .waitsFor pour chaque Vue
		     .waitsFor(created(VueA.class))
		     .waitsFor(created(VueB.class))

		     .executes(inputs -> {

		    	 Ntro.newEvent(EvtB.class).trigger();

		     });
	}

}
