package meerkat.voting.gui.controllersFX;

/**
 * Created by Laura on 12/16/2016.
 */
import javafx.fxml.FXML;
import javafx.scene.Node;
import javafx.scene.Parent;
import javafx.scene.layout.StackPane;
import meerkat.protobuf.Voting;
import meerkat.voting.controller.callbacks.VoterCancelThrowable;
import meerkat.voting.gui.ui.CommandPend;
import org.slf4j.Logger;
import meerkat.voting.gui.ui.uicommands.ChannelChoiceUICommand;
import meerkat.voting.gui.ui.uicommands.UICommand;

import java.io.IOException;
import java.util.List;

/**
 * Main controller class for the entire layout.
 */
public class MainController {

    private CommandPend<UICommand> cmdPend;

    /** Holder of a switchable vista. */
    @FXML
    private StackPane vistaHolder;

    public void init() {
        cmdPend = new CommandPend<>();
    }

    /**
     * Replaces the vista displayed in the vista holder with a new vista.
     *
     * @param node the vista node to be swapped in.
     */
    public void setVista(Node node) {
        vistaHolder.getChildren().setAll(node);
    }

    public void setCurrentCommand(UICommand command) {
        cmdPend.trample(command);
    }

    public UICommand getCurrentCommand() {
        try {
            return cmdPend.take();
        } catch (InterruptedException e) {
            e.printStackTrace();
            return null;
        }
    }

}