package meerkat.voting.gui.panels.cast_or_audit;

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

    private final Logger logger = LoggerFactory.getLogger(CastOrAuditLoader.class);
    private static final String CAST_OR_AUDIT_FXML_PATH = "/view/cast_or_audit.fxml";

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

    public CastOrAuditLoader(Stage primaryStage, VotingBoothConfiguration config) throws IOException
    {
        this.fxmlLoader = new FXMLLoader(getClass().getResource(CAST_OR_AUDIT_FXML_PATH));
        this.currentStage = primaryStage;
        this.config = config;
        this.logger.debug("Created cast or audit loader object.");
    }

    /**
     * Creates welcome splash parent node and sets it to the controller
     * @return TwoWayNode        controller.SetCurrentScene(thankForAuditing);
     * @throws IOException
     */
    public TwoWayNode GetCastOrAudit() throws IOException {
        Parent castOrAudit = fxmlLoader.load();
        CastOrAuditController controller = fxmlLoader.getController();

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

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

        this.logger.debug("Returns cast or qaudit controller object.");
        return controller;
    }

}
