package meerkat.voting.gui.panels.ballot_summary;

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.
 * BallotSummaryLoader gives the option to whatch summary of voter actions
 */
public class BallotSummaryLoader {

    private final Logger logger = LoggerFactory.getLogger(BallotSummaryLoader.class);
    private static final String BALLOT_SUMMARY_FXML_PATH = "/view/ballot_summary.fxml";

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

    public BallotSummaryLoader(Stage primaryStage, VotingBoothConfiguration config) throws IOException
    {
        this.fxmlLoader = new FXMLLoader(getClass().getResource(BALLOT_SUMMARY_FXML_PATH));
        this.currentStage = primaryStage;
        this.config = config;
        this.logger.debug("Created ballot summary loader object.");
    }

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

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

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

        this.logger.debug("Returns ballot summary controller object.");
        return controller;
    }

}
