package ch.zhaw.gartenverwaltung;


import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;

public class TutorialController {

    @FXML
    public Button previousPageButton;
    @FXML
    public Button nextPageButton;
    @FXML
    public StackPane tourPages;
    public ImageView imgAddNewPlant;
    public ImageView imgTaskList;
    public ImageView imgSelectDate;

    private int page = 0;

    @FXML
    public void initialize() {
        switchViews();
        setButtonAbilities();

        Image placeholder = new Image(String.valueOf(PlantsController.class.getResource("placeholder.png")));
        imgAddNewPlant.setImage(placeholder);
        imgSelectDate.setImage(placeholder);
        imgTaskList.setImage(placeholder);
    }

    public void viewNextPage() {
        page++;
        switchViews();
        setButtonAbilities();
    }
    public void viewPreviousPage() {
        page--;
        switchViews();
        setButtonAbilities();
    }

    private void setButtonAbilities() {
        previousPageButton.setDisable(page <= 0);
        nextPageButton.setDisable(page >= tourPages.getChildren().size() - 1);
    }

    private void switchViews() {
        tourPages.getChildren().forEach(node -> node.setOpacity(0));
        tourPages.getChildren().get(page).setOpacity(1);
    }

    public void closeTutorial() {
        Stage root = (Stage) tourPages.getScene().getWindow();
        root.close();
    }
}
