package com.example.happy_bird;

import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.Slider;
import javafx.scene.control.TextField;
import javafx.scene.image.Image;
import javafx.scene.layout.*;
import javafx.scene.text.TextAlignment;

public class FormatingClass {
    /***
     * leerer Konstruktor
     */
    public FormatingClass() { }

    /*** Alteköster
     * Formatiert alle Buttons und fügt sie der Pane hinzu
     * @param buttons   ButtonArray mit allen Arrays
     * @param pane      Pane, auf der die Buttons angezeigt werden
     */
    public void buttonsFormating(Button[] buttons, Pane pane) {
        for (Button button : buttons) {
            button.setPrefSize(200, 50);

            button.setStyle("-fx-background-color: #e86000; " +
                    "-fx-text-fill: #FFFFFF; " +
                    "-fx-font-size: 20px; " +
                    "-fx-border-width: 5px;" +
                    "-fx-border-color: #FFFFFF;" +
                    "-fx-font-weight: bold;" +
                    "-fx-border-radius: 15px;" +
                    "-fx-background-radius: 20px;");

            pane.getChildren().add(button);
        }
    }

    /*** Alteköster
     * Formatiert alle kleinen Labels (keine Überschrift) und fügt sie der Pane hinzu
     * @param labels    LabelArray mit allen Labels
     * @param pane      Pane, auf der die Labels angezeigt werden
     */
    public void labelsFormating(Label[] labels, Pane pane) {
        for (Label label : labels) {
            label.setPrefSize(250, 50);

            label.setStyle("-fx-background-color: #DED894; " +
                    "-fx-text-fill: #000000; " +
                    "-fx-font-size: 20px; " +
                    "-fx-border-width: 5px;" +
                    "-fx-border-color: #543847;" +
                    "-fx-font-weight: bold;" +
                    "-fx-alignment: center;" +
                    "-fx-background-radius: 20px;" +
                    "-fx-border-radius: 15px;");

            pane.getChildren().add(label);

            label.setVisible(false);
        }
    }

    /*** Alteköster
     * Formatiert alle Überschriften-Labels und fügt sie der Pane hinzu
     * @param labels    LabelArray mit Überschriften-Labels
     * @param pane      Pane, auf der die Labels angezeigt werden
     */
    public void headlineFormating(Label[] labels, Pane pane) {
        for (Label label : labels) {
            label.setPrefSize(300, 75);
            label.setTextAlignment(TextAlignment.CENTER);

            label.setStyle("-fx-background-color: #DED894; " +
                    "-fx-text-fill: #000000; " +
                    "-fx-font-size: 35px; " +
                    "-fx-border-width: 5px;" +
                    "-fx-border-color: #543847;" +
                    "-fx-font-weight: bold;" +
                    "-fx-alignment: center;" +
                    "-fx-background-radius: 20px;" +
                    "-fx-border-radius: 15px;");

            pane.getChildren().add(label);
        }
    }

    /*** Alteköster
     * Formatiert alle Textfelder und fügt sie der Pane hinzu
     * @param textfields    TextFieldArray mit allen Textfeldern
     * @param pane          Pane, auf der die Textfelder angezeigt werden
     */
    public void textfieldsFormating(TextField[] textfields, Pane pane) {
        for (TextField field : textfields) {
            field.setPrefSize(250, 50);
            field.setStyle("-fx-font-size: 20px;" +
                    "-fx-font-weight: bold;");

            pane.getChildren().add(field);

            field.setVisible(false);
        }
    }

    /*** Alteköster
     * Formatiert den soundSlider und fügt ihn der Pane hinzu
     * @param slider    SoundSlider
     * @param pane      Pane, auf der der Slider angezeigt wird
     */
    public void soundSliderFormating(Slider slider, Pane pane) {
        slider.setPrefSize(200, 5);
        slider.setLayoutX(300);
        slider.setLayoutY(295);

        pane.getChildren().add(slider);

        slider.setVisible(false);
    }

    /*** Alteköster
     * Formatiert den PauseScreen
     */
    public void pauseScreenFormating(Pane pause, Label pauseMenuLabel, Label soundLabelPause) {
        /*pause-Pane formatieren*/
        pause.setPrefSize(400, 400);
        pause.setLayoutX(200);
        pause.setLayoutY(150);
        pause.setStyle("-fx-background-color: #DED894; " +
                "-fx-border-width: 5px;" +
                "-fx-border-color: #543847;" +
                "-fx-border-radius: 15px;" +
                "-fx-background-radius: 20px;");

        /*pauseMenuLabel formatieren*/
        pauseMenuLabel.setPrefSize(300,50);
        pauseMenuLabel.setLayoutX(50);
        pauseMenuLabel.setLayoutY(10);
        pauseMenuLabel.setStyle("-fx-background-color: #DED894; " +
                "-fx-text-fill: #000000; " +
                "-fx-font-size: 35px; " +
                "-fx-font-weight: bold;" +
                "-fx-alignment: center;");

        /*soundLabelPause formatieren*/
        soundLabelPause.setPrefSize(100, 50);
        soundLabelPause.setLayoutX(150);
        soundLabelPause.setLayoutY(100);
        soundLabelPause.setStyle("-fx-background-color: #DED894; " +
                "-fx-text-fill: #000000; " +
                "-fx-font-size: 20px; " +
                "-fx-font-weight: bold;" +
                "-fx-alignment: center;");
    }

    /*** Pape
     * formatiert den End-Screen
     */
    public void endScreenFormating(Pane endScreen, Label endScreenHeadline, Label currentScoreEndscreenLabel) {
        /*Endscreen-Pane formatieren*/
        endScreen.setPrefSize(400, 500);
        endScreen.setLayoutX(200);
        endScreen.setLayoutY(100);
        endScreen.setStyle("-fx-background-color: #DED894; " +
                "-fx-border-width: 5px;" +
                "-fx-border-color: #543847;" +
                "-fx-border-radius: 15px;" +
                "-fx-background-radius: 20px;");

        endScreenHeadline.setPrefSize(300,50);
        endScreenHeadline.setLayoutX(50);
        endScreenHeadline.setLayoutY(10);
        endScreenHeadline.setStyle("-fx-background-color: #DED894; " +
                "-fx-text-fill: #000000; " +
                "-fx-font-size: 35px; " +
                "-fx-font-weight: bold;" +
                "-fx-alignment: center;");

        currentScoreEndscreenLabel.setPrefSize(300,50);
        currentScoreEndscreenLabel.setLayoutX(50);
        currentScoreEndscreenLabel.setLayoutY(100);
        currentScoreEndscreenLabel.setStyle("-fx-background-color: #DED894; " +
                "-fx-text-fill: #000000; " +
                "-fx-font-size: 35px; " +
                "-fx-font-weight: bold;" +
                "-fx-alignment: center;");
    }

    /*** Alteköster
     * Erstellt ein neues BackgroundImage aus einer Source für ein .png
     * @param img   Source eines .png
     * @return      backgroundImage
     */
    public BackgroundImage backgroundFormating(String img) {
        /*Bild für Hintergrund erstellen:*/
        Image image = new Image(img);

        /*Hintergrund erstellen:*/
        BackgroundImage backgroundImage = new BackgroundImage(
                image,
                BackgroundRepeat.NO_REPEAT,
                BackgroundRepeat.NO_REPEAT,
                BackgroundPosition.DEFAULT,
                BackgroundSize.DEFAULT
        );

        return backgroundImage;
    }

    /*** Alteköster
     * Formatiert die Buttons, mit denen man das Hintergrundbild ändern kann
     * @param backgroundButtons Array der Buttons
     * @param pane              Pane, auf der die Buttons angezeigt werden sollen
     */
    public void backgroundButtonsFormating(Button[] backgroundButtons, Pane pane) {
        int xPosition = 150;

        for(int i=0; i<backgroundButtons.length; i++) {
            backgroundButtons[i].setPrefSize(200, 175);
            backgroundButtons[i].setLayoutY(400);
            backgroundButtons[i].setLayoutX(xPosition);
            xPosition += 300;

            /*Source als String*/
            String img = "file:src/main/resources/com/example/happy_bird/pics/Background"+i+"button.png";

            /*Hintergrund zu Pane hinzufügen:*/
            Background background = new Background(backgroundFormating(img));

            backgroundButtons[i].setBackground(background);

            backgroundButtons[i].setStyle("-fx-border-width: 7px;" +
                    "-fx-border-insets: -7;" +
                    "-fx-border-color: #FFFFFF;" +
                    "-fx-border-radius: 15px;");

            pane.getChildren().add(backgroundButtons[i]);
        }
    }
}
