package depart.frontal.vues;

import ca.ntro.app.Ntro;
import ca.ntro.app.frontend.ViewFx;
import depart.commun.messages.MsgA;
import depart.frontal.evenements.EvtB;
import depart.maquettes.MaquetteDepart;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.layout.Pane;
import depart.frontal.fragments.FragmentA;
import ca.ntro.app.frontend.ViewLoader;
import depart.commun.valeurs.ValeurA;

public class VueA extends ViewFx {

	@FXML
	private Label labelA;

	@FXML
	private Button boutonA;

	@FXML
	private Button boutonB;

	@FXML
	private Label labelB;

	@FXML
	private Pane conteneurA;

	
	private ViewLoader<FragmentA> viewLoader;

	@Override
	public void initialize() {
		Ntro.assertNotNull(labelA);
		Ntro.assertNotNull(boutonA);
		Ntro.assertNotNull(boutonB);
		Ntro.assertNotNull(labelB);
		Ntro.assertNotNull(conteneurA);
		
		boutonA.setOnAction(evtFx -> {

			Ntro.newEvent(EvtB.class).trigger();
			
		});
		
		boutonB.setOnAction(evtFx -> {
			
			Ntro.newMessage(MsgA.class)
			    .setParamA(MaquetteDepart.chaineAuHasard())
			    .setParamB(MaquetteDepart.entierAuHasard())
			    .send();
			
		});
	}

	public void methodeA(String paramA) {
		labelA.setText(paramA);
	}

	public void methodeB(ViewLoader<FragmentA> paramA) {
		this.viewLoader = paramA;
	}

	public void methodC(boolean paramA) {
		labelA.setText(String.valueOf(paramA));
	}

	public void methodD(double paramB) {
		labelB.setText(String.valueOf(paramB));
	}

	public void methodeE() {
		conteneurA.getChildren().clear();
	}

	public void methodeF(ValeurA paramC) {
		FragmentA varA = viewLoader.createView();
		paramC.methodeA(varA);
		
		conteneurA.getChildren().add(varA.rootNode());
	}

}
