package cz.vutbr.feec.gui;

import java.awt.Dialog;

import cz.vutbr.feec.libraryClasses.GuiMethods;
import cz.vutbr.feec.project.GlobalParameters;
import cz.vutbr.feec.stockElements.Stock;
import cz.vutbr.feec.transportObjects.PositionCrate;
import javafx.application.Application;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.concurrent.Task;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.Button;
/*
import javafx.scene.control.Dialogs.DialogOptions;
import javafx.scene.control.Dialogs.DialogResponse;
import javafx.scene.control.Dialogs;
*/
import javafx.scene.control.Label;
import javafx.scene.control.ProgressBar;
import javafx.scene.control.TextField;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.HBox;
import javafx.stage.Stage;
import javafx.util.Callback;

public class ProgressBarRoutingTable extends Application {
	/*
	 * private Stock s = Stock.getInstance(); public static ProgressBar pb = new
	 * javafx.scene.control.ProgressBar(); Stage stage = new Stage();
	 * 
	 * public ProgressBarRoutingTable() { GridPane grid = new GridPane();
	 * grid.setHgap(10); grid.setVgap(10); grid.setPadding(new Insets(0, 10, 0,
	 * 10)); pb.setPrefWidth(300);
	 * 
	 * grid.add(new Label("Progress: "), 0, 0); grid.add(pb, 1, 0); grid.add(new
	 * Label("After computing routing table click on 'Ok' or"), 1, 1);
	 * grid.add(new Label("you can cancel this operation by click on 'Cancel'"),
	 * 1, 2);
	 * 
	 * Callback myCallback = new Callback() {
	 * 
	 * @Override public Object call(Object arg0) { // TODO Auto-generated method
	 * stub return null; }
	 * 
	 * }; /*
	 * 
	 * @Override public Object call(Object param) { // TODO Auto-generated
	 * method stub lengthResult = length.getText(); widthResult =
	 * width.getText(); return null; } };
	 */
	/*
	 * DialogResponse resp = Dialogs.showCustomDialog(
	 * GlobalParameters.primaryStage, grid,
	 * "Please wait until routing table will be complete",
	 * "Computing routing table", DialogOptions.OK_CANCEL, myCallback); if (resp
	 * == DialogResponse.OK) { //stlacilo sa ok... //ak je to pocas vypoctu //
	 * if(stale pocitam..)
	 * Dialogs.showWarningDialog(GlobalParameters.primaryStage,
	 * "Please wait until routing table will be complete.",
	 * "Routing table in progress...", ""); // nechaj dobehnut - vytvor iba nove
	 * okno znovu ProgressBarRoutingTable pb = new ProgressBarRoutingTable();
	 * //po vypocte - zmen text // if(dopocitala sa RT)
	 * 
	 * 
	 * 
	 * 
	 * } else { if (proceedCancel()) { // potvrdilo sa, vraciam sa spatky na
	 * creating tab System.out.println("confirmed"); } else{ // nechaj dobehnut
	 * - vytvor iba nove okno znovu ProgressBarRoutingTable pb = new
	 * ProgressBarRoutingTable(); } } }
	 * 
	 * private boolean proceedCancel() { DialogResponse response =
	 * Dialogs.showConfirmDialog( GlobalParameters.primaryStage,
	 * "Do you want to continue?",
	 * "This step will stop computing routing table", null,
	 * DialogOptions.OK_CANCEL); if (response == DialogResponse.OK) { return
	 * true; } else { return false; } }
	 */
	private final Label label = new Label();
	public static ProgressBar pb = new ProgressBar();
	private final Button cancelButton = new Button("Cancel");
	final HBox hb = new HBox();
	private double value = 0;
	private int size;
	static Stage stage;

	@Override
	public void start(final Stage stage) {
		Group root = new Group();
		Scene scene = new Scene(root, 300, 150);
		stage.setScene(scene);
		stage.setMinHeight(150);
		stage.setMinWidth(300);
		stage.setTitle("Computing Routing Table");
		this.stage = stage;

		label.setText("Progress: ");
		/*
		 * final ProgressIndicator pin = new ProgressIndicator();
		 * pin.setProgress(value);
		 */
		hb.setSpacing(10);
		hb.setAlignment(Pos.CENTER);
		pb.setProgress(value);
		// hb.getChildren().addAll(label, pb, labelPerc, pin );
		hb.getChildren().addAll(label, pb, cancelButton);

		cancelButton.setOnAction(new EventHandler<ActionEvent>() {
			public void handle(ActionEvent event) {
				cancelButton.setDisable(true);
				pb.progressProperty().unbind();
				System.out.println("cancelled.");
				stage.close();
				
			}
		});

		scene.setRoot(hb);
		stage.show();

	}

	public void setProgress(double d, int size) {
		value = (float) d;
		this.size = size;
	}

	public double getProgress() {
		return value;
	}

	public void closeStage() {
		stage.close();
	}

}
