package harmony.mastermind.ui;

import javafx.scene.Node;
import javafx.scene.control.TextArea;
import javafx.scene.control.TextField;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyEvent;
import javafx.scene.layout.GridPane;
import javafx.scene.text.Text;
import javafx.event.EventHandler;
import javafx.fxml.FXML;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.stage.Popup;

//@@author A0139194X
public class HelpPopup extends UiPart {

    private static final String FXML = "HelpPopup.fxml";
    private Popup popup;
    private TextArea content;
    private boolean isFirstKey;

    //@@author A0139194X
    public HelpPopup() {
        initPopup();
        isFirstKey = true;
    }

    //@@author A0139194X
    public void show(Node node) {
        popup.show(node, 200, 100);
        popup.centerOnScreen();
    }

    //@@author A0139194X
    @Override
    public void setNode(Node node) {
    }

    //@@author A0139194X
    @Override
    public String getFxmlPath() {
        return FXML;
    }
    
    //@@author A0139194X
    @FXML
    private void initPopup() {
        popup = new Popup();
        content = new TextArea();
        properties();

        popup.getContent().add(content);
        popup.addEventHandler(KeyEvent.KEY_RELEASED, keyEventHandler);

        content.setEditable(false);
    }

    //@@author A0139194X
    @FXML
    EventHandler<KeyEvent> keyEventHandler = new EventHandler<KeyEvent>() {
        public void handle(KeyEvent event) {
            if (!isFirstKey && event.getCode() != null) {
                popup.hide();
            }
            isFirstKey = !isFirstKey;
        }
    };

    //@@author A0139194X
    public void setContent(String text) {
        content.setText(text);
    }
    
    //@@author A0143378Y
    public void properties() { 
        //Setting up the width and height
        content.setPrefHeight(800);
        content.setPrefWidth(1000);
        
        //Setting up wrapping of text in the content box 
        content.setWrapText(true);
        
        //Setting up the background, font and borders
        content.setStyle("-fx-background-color: yellow;"
                + "-fx-padding:8px;"
                + "-fx-text-fill: #000080;"
                + "-fx-font-family: fantasy;"
                + "-fx-alignment: center;" 
                + "-fx-font-size: 20px;"
                );

//        content.setStyle("-fx-font-family: sample; -fx-font-size: 20;");
    }
}

@@ -2166,36 +2166,16 @@
 or: 
-yellow;%22%0A                + %22
+#00BFFF;
 -fx-
@@ -2182,17 +2182,18 @@
 padding:
-8
+10
 px;%22%0A   
@@ -2232,33 +2232,16 @@
 000080;%22
-%0A                
 + %22-fx-f
@@ -2256,15 +2256,16 @@
 ly: 
-fant
+Consol
 as
-y
 ;%22%0A 
@@ -2307,51 +2307,8 @@
 nter
-;%22 %0A                + %22-fx-font-size: 20px;
 %22%0A  

Revert "minor edits to popup window"