package fr.insa.clavardator.client;

import fr.insa.clavardator.client.ui.MainController;
import fr.insa.clavardator.lib.util.Log;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;

// See here : https://github.com/jfoenixadmin/JFoenix/blob/master/demo/src/main/java/demos/components/DrawerDemo.java

public class MainApp extends Application {

	private MainController mainController;

	public static void main(String[] args) {
		launch(args);
	}

	@Override
	public void start(Stage stage) throws Exception {
		Log.verboseLevel = 4;
		Log.v("START", "Application started");

		final FXMLLoader mainLoader = new FXMLLoader(getClass().getResource("ui/scene.fxml"));
		final Parent content = mainLoader.load();
		mainController = mainLoader.getController();

		Scene scene = new Scene(content);

		stage.setScene(scene);
		stage.setTitle("Clavardator");
		stage.setMinHeight(640);
		stage.setMinWidth(800);
//		stage.setMaximized(true);
		stage.show();
	}

	@Override
	public void stop() throws Exception {
		// Stop all threads and active connections before exiting
		if (mainController != null) {
			mainController.stop();
		}
		super.stop();
	}
}