package meerkat.voting.gui.panels.select_candidate_by_picture;

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.
 * SelectCandidateByPictureLoader creates the pannel which gives the option to choose by picture
 */
public class SelectCandidateByPictureLoader {

    private final Logger logger = LoggerFactory.getLogger(SelectCandidateByPictureLoader.class);
    private static final String SELECT_CANDIDATE_BY_PICTURE_FXML_PATH = "/view/select_candidate_by_picture.fxml";

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

    public SelectCandidateByPictureLoader(Stage primaryStage, VotingBoothConfiguration config) throws IOException
    {
        this.fxmlLoader = new FXMLLoader(getClass().getResource(SELECT_CANDIDATE_BY_PICTURE_FXML_PATH));
        this.currentStage = primaryStage;
        this.config = config;
        this.logger.debug("Created the select candidate by picture loader object.");
    }

    /**
     * Creates welcome splash parent node and sets it to the controller
     * @return TwoWayNode
     * @throws IOException
     */
    public TwoWayNode GetSelectCandidateByPicture() throws IOException {
        Parent selectByPicture = fxmlLoader.load();
        meerkat.voting.gui.panels.select_candidate_by_picture.SelectCandidateByPictureController controller = fxmlLoader.getController();

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

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

        this.logger.debug("Created select candidate by picture controller object.");
        return controller;
    }

}
