package controllers;


import javafx.fxml.Initializable;
import javafx.scene.control.Alert;
import javafx.scene.control.ButtonType;
import model.SceneCode;

import java.util.Optional;

/**
 * Created by Gondr on 4/04/2017.
 */
public abstract class Controller implements Initializable {

    protected Main parent;

    public Controller(){

    }

    public void setParent(Main parent){
        this.parent = parent;
    }

    public Controller changeScene(SceneCode scene) throws Exception {
        return parent.replaceSceneContent(scene);
    }

    public void runLater(){

    }

    public Optional<ButtonType> popUp(Alert.AlertType alertType, String title, String header, String content, ButtonType[] buttons){
        Alert alert = new Alert(alertType);
        alert.setTitle(title);
        alert.setHeaderText(header);
        alert.setContentText(content);
        alert.getButtonTypes().remove(0, alert.getButtonTypes().size()); // remove all buttons
        for (int i = 0; i < buttons.length; i ++){
            alert.getButtonTypes().add(buttons[i]);
        }
        return alert.showAndWait();
    }

    public Optional<ButtonType> popUp(Alert.AlertType alertType, String title, String header, String content){
        Alert alert = new Alert(alertType);
        alert.setTitle(title);
        alert.setHeaderText(header);
        alert.setContentText(content);
        return alert.showAndWait();
    }

}
