package com.moviesdb;

import javafx.fxml.FXML;
import javafx.scene.control.*;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.stage.Stage;

import java.util.Objects;


public class Controller {

    @FXML
    Label minimizeButton;

    @FXML
    Label maximizeButton;

    @FXML
    Label closeButton;

    public Stage stage;


    public void prepare() {
        setWindowControlImage(minimizeButton, "../../media\\minimize.png");
        setWindowControlImage(maximizeButton, "../../media\\maximize.png");
        setWindowControlImage(closeButton, "../../media\\cancel.png");
    }

    @FXML
    private void closeStage(){
        stage.close();
    }

    @FXML
    private void maximizeStageChange(){
        stage.setMaximized(!stage.isMaximized());
    }

    @FXML
    private void minimizeStage(){
        stage.setIconified(true);
    }

    private void setWindowControlImage(Label target, String imagePath){
        try {
            if (!Objects.isNull(target)) {
                ImageView CloseImageView = new ImageView(new Image(Objects.requireNonNull(getClass().getResourceAsStream(imagePath))));
                CloseImageView.setFitHeight(16);
                CloseImageView.setFitWidth(16);
                target.setGraphic(CloseImageView);
            }
        } catch (NullPointerException e) {
            e.printStackTrace();
        }
    }
}
