package meerkat.voting.gui.panels.vote_have_been_cast;

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.
 * VoteHaveBeenCastLoader laods the screen that in charge of handling the voting end
 */
public class VoteHaveBeenCastLoader {
    private final Logger logger = LoggerFactory.getLogger(VoteHaveBeenCastLoader.class);

    private static final String VOTE_HAVE_BEEN_CAST_FXML_PATH = "/view/vote_have_been_cast.fxml";

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

    public VoteHaveBeenCastLoader(Stage primaryStage ,VotingBoothConfiguration config) throws IOException
    {
        this.fxmlLoader = new FXMLLoader(getClass().getResource(VOTE_HAVE_BEEN_CAST_FXML_PATH));
        this.currentStage = primaryStage;
        this.config = config;
        this.logger.debug("Created the vote have been cast loader.");
    }

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

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

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

        this.logger.debug("Created the vote have been cast controller.");
        return controller;
    }
}
