package game.menu;

import game.Main;
import game.player.Player;
import game.player.Type;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.HPos;
import javafx.geometry.Insets;
import javafx.scene.Group;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.layout.ColumnConstraints;
import javafx.scene.layout.GridPane;
import javafx.scene.paint.Color;

public class Menu {
    private Group group;
    private StatusMenu status;
    private Player playerGame;

    public Menu(Group group, StatusMenu status, Player playerGame) {
        this.group = group;
        this.playerGame = playerGame;
        this.status = status;
        group.getChildren().add(this.createButton());
        group.getChildren().add(this.createGridMenu());
    }

    private GridPane createGridMenu() {
        GridPane gridMenu = new GridPane();
        gridMenu.setPadding(new Insets(5));
        gridMenu.setHgap(5);
        gridMenu.setVgap(5);
        ColumnConstraints columnOne = new ColumnConstraints(100);
        ColumnConstraints columnTwo = new ColumnConstraints(50, 100, 200);
        gridMenu.getColumnConstraints().addAll(columnOne, columnTwo);

        Label health = new Label("Health:");
        health.setTextFill(Color.web("#FFFFFF"));
        Label healthValue = new Label(status.getHealth() + "");
        healthValue.setTextFill(Color.web("#A40013"));
        GridPane.setHalignment(health, HPos.LEFT);
        GridPane.setHalignment(healthValue, HPos.RIGHT);
        gridMenu.add(health, 0, 0);
        gridMenu.add(healthValue, 1, 0);

        Label attack = new Label("Attack:");
        attack.setTextFill(Color.web("#FFFFFF"));
        Label attackValue = new Label(status.getAttack() + "");
        attackValue.setTextFill(Color.web("#A40013"));
        GridPane.setHalignment(attack, HPos.LEFT);
        GridPane.setHalignment(attackValue, HPos.RIGHT);
        gridMenu.add(attack, 0, 1);
        gridMenu.add(attackValue, 1, 1);

        Label defence = new Label("Defence:");
        defence.setTextFill(Color.web("#FFFFFF"));
        Label defenceValue = new Label(status.getDefence() + "");
        defenceValue.setTextFill(Color.web("#A40013"));
        GridPane.setHalignment(defence, HPos.LEFT);
        GridPane.setHalignment(defenceValue, HPos.RIGHT);
        gridMenu.add(defence, 0, 2);
        gridMenu.add(defenceValue, 1, 2);

        Label experience = new Label("Experience:");
        experience.setTextFill(Color.web("#FFFFFF"));
        Label experienceValue = new Label(status.getExperience() + "");
        experienceValue.setTextFill(Color.web("#A40013"));
        GridPane.setHalignment(experience, HPos.LEFT);
        GridPane.setHalignment(experienceValue, HPos.RIGHT);
        gridMenu.add(experience, 0, 3);
        gridMenu.add(experienceValue, 1, 3);
        gridMenu.setLayoutX(1000);
        gridMenu.setLayoutY(10);

        return gridMenu;
    }

    private Button createButton() {
        Button player = new Button();
        player.setText("Create Player");
        player.setLayoutX(880);
        player.setLayoutY(20);
        player.setOnAction(new EventHandler<ActionEvent>() {
            @Override
            public void handle(ActionEvent event) {
                TextField user = new TextField();
                user.setPromptText("Username");

                Button start = new Button();
                start.setText("Start Game");
                start.setOnAction(new EventHandler<ActionEvent>() {
                    @Override
                    public void handle(ActionEvent event) {
                        String username = user.getText();
                        Menu.this.playerGame = new Player(username, Menu.this.status, Type.USER);
                        Object a = Menu.this.group.getChildren().remove(3); //remove grid with username field
                        //TODO render again status menu
                    }
                });

                GridPane grid = new GridPane();
                grid.setLayoutX(450);
                grid.setLayoutY(350);
                grid.setVgap(5);
                grid.setHgap(5);
                grid.setPadding(new Insets(5, 5, 5, 5));
                grid.add(user, 0, 0);
                grid.add(start, 1, 0);

                Menu.this.group.getChildren().add(grid);
            }
        });

        return player;
    }

    public void updateGridMenu(StatusMenu status) {

    }
}

@@ -29,12 +29,26 @@
 ame.
-Main
+player.Personality
 ;%0Aim
@@ -527,39 +527,8 @@
 up;%0A
-    private StatusMenu status;%0A
     
@@ -587,27 +587,8 @@
 oup,
- StatusMenu status,
  Pla
@@ -675,38 +675,8 @@
 me;%0A
-        this.status = status;%0A
     
@@ -780,32 +780,162 @@
 Menu());%0A    %7D%0A%0A
+    public void updateGridMenu() %7B%0A        //this.group.getChildren().remove(2)%0A        System.out.println(%22update grid%22);%0A    %7D%0A%0A
     private Grid
@@ -1453,26 +1453,34 @@
 bel(
-status.getHealth()
+Personality.HEALTH_DEFAULT
  + %22
@@ -1861,26 +1861,34 @@
 bel(
-status.getAttack()
+Personality.ATTACK_DEFAULT
  + %22
@@ -2273,27 +2273,35 @@
 bel(
-status.getDefence()
+Personality.DEFENCE_DEFAULT
  + %22
@@ -2703,30 +2703,38 @@
 bel(
-status.getExperience()
+Personality.EXPERIENCE_DEFAULT
  + %22
@@ -3887,26 +3887,8 @@
 ame,
- Menu.this.status,
  Typ
@@ -3923,19 +3923,8 @@
     
- Object a =
  Men
@@ -4495,32 +4495,32 @@
  %7D%0A        %7D);%0A%0A
+
         return p
@@ -4535,67 +4535,7 @@
    %7D
-%0A%0A    public void updateGridMenu(StatusMenu status) %7B%0A%0A    %7D
 %0A%7D%0A

remove statusMenu and using Personality - abstract class