package meerkat.voting.gui.panels.select_candidate_name;

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.
 * SelectCandidateNameLoader creates the option to choose by name
 */
public class SelectCandidateNameLoader {

    private final Logger logger = LoggerFactory.getLogger(SelectCandidateNameLoader.class);
    private static final String SELECT_CANDIDATE_NAME_FXML_PATH = "/view/select_candidate_name.fxml";

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

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

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

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

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

        this.logger.debug("Created and returns the get select candidate name controller object.");
        return controller;
    }

}
