package meerkat.voting.gui.panels.thank_for_audditing;

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 10/5/2016.
 * This class load the pannel that represent the thank u message
 */
public class ThankForAuditingLoader {

    private final Logger logger = LoggerFactory.getLogger(ThankForAuditingLoader.class);
    private static final String THANK_FOR_AUDITING_FXML_PATH = "/view/thank_for_auditing.fxml";

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

    public ThankForAuditingLoader(Stage primaryStage, VotingBoothConfiguration config) throws IOException
    {
        this.fxmlLoader = new FXMLLoader(getClass().getResource(THANK_FOR_AUDITING_FXML_PATH));
        this.currentStage = primaryStage;
        this.config = config;
        this.logger.debug("Created the Thank for auditing Loader object.");
    }

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

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

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

        this.logger.debug("Created the thank for auditing controller object.");
        return controller;
    }
}
