package meerkat.voting.gui.panels.welcome_splash;

import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.stage.Stage;
import meerkat.voting.gui.configuration.VotingBoothConfiguration;
import meerkat.voting.gui.managment.TwoWayNode;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;

/**
 * Created by Vladimir Eliezer Tokarev on 8/27/2016.
 * WelcomeSplashLoader creates welcome spalash object and sets its controller
 */
public class WelcomeSplashLoader {
    private final Logger logger = LoggerFactory.getLogger(WelcomeSplashLoader.class);

    private static final String WELCOME_SPLASH_FXML_PATH = "/view/welcome_splash_screen.fxml";

    private Stage currentStage;
    private FXMLLoader  fxmlLoader;
    private VotingBoothConfiguration config;

    public WelcomeSplashLoader(Stage primaryStage, VotingBoothConfiguration config) throws IOException
    {
        this.logger.debug("Created the welcome splash loader which loads the first pannel.");
        this.fxmlLoader = new FXMLLoader(getClass().getResource(WELCOME_SPLASH_FXML_PATH));
        this.currentStage = primaryStage;
        this.config = config;
    }

    /**
     * Creates welcome splash parent node and sets it to the controller
     * @return TwoWayNode
     * @throws IOException
     */
    public TwoWayNode GetWelcomeSplash() throws IOException {
        Parent welcomeSplash = this.fxmlLoader.load();
        WelcomeSplashController controller = this.fxmlLoader.getController();

        // set the controller to be functional TwoWayNode
        controller.SetCurrentScene(welcomeSplash);
        controller.SetStage(currentStage);

        // set the controller to have the configuration file
        controller.SetConfig(this.config);

        this.logger.debug("Created the welcome splash controller.");
        return controller;
    }
}
