package net.starbs.antipleurdawn.handlers;

import javafx.application.Platform;
import javafx.scene.Scene;
import javafx.scene.effect.BoxBlur;
import javafx.scene.layout.FlowPane;
import net.starbs.antipleurdawn.Piece;
import net.starbs.antipleurdawn.client.Client;
import net.starbs.antipleurdawn.events.GameEndedEvent;
import net.starbs.antipleurdawn.events.GameUpdatedEvent;
import net.starbs.antipleurdawn.ui.Board;

public class BoardHandler implements HandlerInterface
{
    private Board board;
    private Client client;
    private Scene scene;

    public BoardHandler(Board board, Client client, Scene scene)
    {
        this.board = board;
        this.client = client;
        this.scene = scene;
    }

    public void onGameUpdated(GameUpdatedEvent event)
    {
        displayCapturedPieces(event.getPiecesTakenBy(client.getPlayer()), event.getPiecesTakenBy(client.getOpponent()));

        board.displayData(event.getBoard());

        if (event.getCurrentPlayer() == client.getPlayer()) {
            System.out.println("Make your move now.");
        } else {
            displayWaitingScreen();
        }
    }

    // TODO
    private void displayCapturedPieces(Piece[] yourCaptures, Piece[] oppCaptures)
    {
//        FlowPane yourCapturesUI = (FlowPane) scene.lookup("yourCaptures");
//        FlowPane oppCapturesUI = (FlowPane) scene.lookup("oppCaptures");
//
//        yourCapturesUI.getChildren().removeAll();
//        oppCapturesUI.getChildren().removeAll();
//
//        for (Piece yourCapture : yourCaptures) {
//            yourCapturesUI.getChildren().add(yourCapture.getImage());
//        }
//
//        for (Piece oppCapture: oppCaptures) {
//            oppCapturesUI.getChildren().add(oppCapture.getImage());
//        }
    }

    private void displayWaitingScreen()
    {
        BoxBlur bb = new BoxBlur();
        bb.setWidth(5);
        bb.setHeight(5);
        bb.setIterations(1);

        scene.lookup("#main").setEffect(bb);
        scene.lookup("#overlay").setStyle("visibility: visible");
    }

    public void onGameEnded(GameEndedEvent event)
    {
        if (event.getWinner() == client.getPlayer()) {
            System.out.println("You win!");
        } else {
            System.out.println("You are a burden on modern society.");
        }
        
        Platform.exit();
    }
}

@@ -1018,48 +1018,26 @@
     
-System.out.println(%22Make your move now.%22
+hideWaitingScreen(
 );%0A 
@@ -2012,32 +2012,190 @@
 sible%22);%0A    %7D%0A%0A
+    private void hideWaitingScreen() %7B%0A        scene.lookup(%22#main%22).setEffect(null);%0A        scene.lookup(%22#overlay%22).setStyle(%22visibility: hidden%22);%0A    %7D%0A%0A
     public void 

Add hideWaitingScreen()