package meerkat.voting.gui.panels.straight_channel_section;

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.
 * StraightChannelSectionLoader creates starlight channel section object and sets its controller
 */
public class StraightChannelSectionLoader {

    private final Logger logger = LoggerFactory.getLogger(StraightChannelSectionLoader.class);

    private static final String STRAIGHT_CHANNEL_LOADER_FXML_PATH = "/view/straight_channel_section.fxml";

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

    public StraightChannelSectionLoader(Stage primaryStage, VotingBoothConfiguration config) throws IOException
    {
        this.fxmlLoader = new FXMLLoader(getClass().getResource(STRAIGHT_CHANNEL_LOADER_FXML_PATH));
        this.currentStage = primaryStage;
        this.config = config;
        this.logger.debug("Created the straight channel section loader object.");
    }

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

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

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

        this.logger.debug("Created the straight channel section controller.");
        return controller;
    }

}
