package meerkat.voting.gui.panels.welcome_splash;

import javafx.fxml.FXML;
import javafx.scene.control.Label;
import javafx.scene.input.MouseEvent;
import meerkat.voting.gui.managment.TwoWayNode;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Created by Vladimir Eliezer Tokarev on 8/27/2016.
 * WelcomeScreenController handle the behavior of welcome splash class
 */
public class WelcomeSplashController extends TwoWayNode {

    private final Logger logger = LoggerFactory.getLogger(WelcomeSplashController.class);
    private final String INVALID_CONFIGURATION_ERROR_TEXT = "The given configuration is invalid please run this voting booth with different configuraiton.";

    @FXML
    private Label ErrorPanel;

    @FXML
    private void StartVotingProcess(MouseEvent mousePressed) {
        this.currentStage.close();
        this.currentStage.setScene(this.next.GetCurrentScene());
        this.next.UpdateNode();
        this.currentStage.show();
        this.logger.debug("Jumping to the select channel object.");
    }

    @Override
    public void UpdateNode() {
        if (this.config == null || !this.config.IsConfigurationValid()){
            RepresentErrorToVoter(INVALID_CONFIGURATION_ERROR_TEXT);
        }
    }

    /**
     * Represents the given string to user in ErrorLabel
     * @param message is the error string to represent to the user
     */
    private void RepresentErrorToVoter(String message) {
        ErrorPanel.setText(message);
        this.currentStage.show();
    }

}
