import java.util.*;

import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.geometry.Insets;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.layout.GridPane;
import javafx.stage.Stage;
import javafx.scene.control.TextArea;

/**
 * This allows the user to buy things from a theortical Minecraft Shop.
 * You will need reference to your Item.java and Shop.java.
 * 
 * TASK:
 * Features it needs:
 * Adding things to the basket
 * Undoing from the basket
 * Finishing the order and printing out how many of each things are present.
 * 
 * Extension:
 * You may extend it in the same way as the previous assignment if you wish. Hopefully the logic will be similar.
 * 
 * Challenge:
 * There are no challenges for this one. You will have to wait for the internal assessment!
 *
 * @author (your name)
 * @version (a version number or a date)
 */
public class ShopperGUI extends Application
{
    // We keep track of the count, and label displaying the count:
    private int emeralds = 200;
    private Stack<Item> basket;
    
    private Label emeraldDisplay = new Label("200");
    private TextArea textOutput = new TextArea();
    

    /**
     * The start method is the main entry point for every JavaFX application. 
     * It is called after the init() method has returned and after 
     * the system is ready for the application to begin running.
     *
     * @param  stage the primary stage for this application.
     */
    @Override
    public void start(Stage stage)
    {
        // Create a Button or any control item
        Button dirt = new Button("Here be Dirt");

        // Create a new grid pane
        GridPane pane = new GridPane();
        pane.setPadding(new Insets(10, 10, 10, 10));
        pane.setMinSize(300, 300);
        pane.setVgap(10);
        pane.setHgap(10);
        pane.setGridLinesVisible(true);//comment this out to get rid of the lines.

        //set an action on the button using method reference
        dirt.setOnAction(this::buyDirt);

        // Add the button and label into the pane
        pane.add(emeraldDisplay, 1, 0);
        pane.add(dirt, 0, 0);
        
        pane.add(textOutput,0,2,5,5);//CHG NOTE!!! These numbers are arbitary! You may wish to place your objects in a different layout.

        Scene scene = new Scene(pane, 600,800);//CHG NOTE!!! The sizes are arbitary! You may wish to place your objects in a different layout.
        stage.setTitle("Shopper GUI");
        stage.setScene(scene);

        // Show the Stage (window)
        stage.show();
        
        
        giveInfo();
        
    }
    
    /**
     * Add a dirt Item to the Basket
     */
    private void buyDirt(ActionEvent event)
    {
        //YOUR CODE HERE
    }

    /**
     * Prints out the information for the user after ALL the GUI stuff has been set up and placed.
     */
    public void giveInfo(){
        printText("Welcome to the shop!");
        printText("Click on the item you want to buy and checkout when you are done!");
        printText("Undo will remove the most recent item on the basket, Clear will empty out the basket.");
        
        printText("Click finish when you are done and your order will be printed out with a summary of the total!");
    }
    
    /**
     * Mr Chuang is being very nice and setting up a function to help you print to the textArea.
     */
    private void printText(String text){
        textOutput.setText(textOutput.getText() + text + "\n");
    }
}
