package meerkat.voting.gui.panels.ballot_summary;

import javafx.fxml.FXML;
import javafx.scene.input.MouseEvent;
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.
 * BallotSummaryController handle the behavior of ballot summary screen
 */
public class BallotSummaryController extends TwoWayNode {

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

    @FXML
    private void GetToSelectByPicture(MouseEvent mousePressed){
        this.currentStage.close();
        this.currentStage.setScene(this.previous.GetCurrentScene());
        this.previous.UpdateNode();
        this.currentStage.show();
        this.logger.debug("Jumping to select candidate by picture panel.");
    }

    @FXML
    private void GetToCastOrAudit(MouseEvent mousePressed){
        this.currentStage.close();
        this.currentStage.setScene(this.next.GetCurrentScene());
        this.next.UpdateNode();
        this.currentStage.show();
        this.logger.debug("Jumping to cast or audit panel.");
    }

    /**
     * This method activates the representor of all the voters choises
     */
    private void ShowAllVotersChoices() throws IOException {
        VotersChoicesAdder votersChoicesAdder = new VotersChoicesAdder(this.currentStage, this.votersBallot);
        votersChoicesAdder.ShowVotersChoices();
        this.logger.debug("Created voters choises adder and added all the choises.");
    }

    @Override
    public void UpdateNode() {
        try {
            this.ShowAllVotersChoices();
            this.logger.debug("Showed all the voters answers.");
        } catch (IOException e) {
            this.logger.error(e.getMessage());
        }
    }
}
