package io.github.marmer.workinghourmanager;

import java.net.URL;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;

import javafx.application.Application;
import javafx.application.Platform;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
import lombok.extern.java.Log;

/**
 * Main class and entrypoint.
 */
@Log
@SpringBootApplication
public class WorkingHourManagerApplication extends Application {

	private ConfigurableApplicationContext springContext;

	private Parent rootNode;

	/**
	 * The main method.
	 *
	 * @param args
	 *            the arguments
	 */
	public static void main(final String... args) {
		launch(args);
	}

	@Override
	public void init() throws Exception {
		log.info("Application starts");
		Platform.setImplicitExit(true);
		springContext = SpringApplication.run(WorkingHourManagerApplication.class);
		URL location = WorkingHourManagerApplication.class.getResource("view/booking/BookingPane.fxml");
		FXMLLoader loader = new FXMLLoader(location);
		loader.setControllerFactory(springContext::getBean);
		rootNode = loader.load();
	}

	@Override
	public void start(final Stage stage) throws Exception {
		stage.setScene(new Scene(rootNode));
		stage.show();
	}
}
