package com.mycompany.fys;

import java.io.IOException;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Node;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyEvent;
import javafx.scene.layout.Pane;
import javafx.stage.Stage;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.PDPage;
import org.apache.pdfbox.pdmodel.PDPageContentStream;
import org.apache.pdfbox.pdmodel.font.PDType1Font;
/**
 *
 * @author shabier
 */
public class statisticsController {

    @FXML
    private Pane hamburgerMenuPane;
    @FXML
    private boolean visibleHamburgerMenu;

    @FXML
    public void openHelp(ActionEvent event) throws IOException {
        Parent root = FXMLLoader.load(getClass().getResource("/fxml/helpPopup.fxml"));
        final Scene scene = new Scene(root);
        final Stage stage = new Stage();
        stage.setTitle("Help");
        stage.setScene(scene);
        stage.show();
        stage.setResizable(false);
        stage.centerOnScreen();

        root.setOnKeyPressed(new EventHandler<KeyEvent>() {
            public void handle(KeyEvent ke) {
                if (ke.getCode() == KeyCode.ESCAPE) {
                    System.out.println("Key Pressed: " + ke.getCode());
                    stage.close();
                }
            }
        });
    }

    @FXML
    public void printPDFFile(ActionEvent event) throws IOException {
        try {
            String fileName = "PDFoutput.pdf";

            PDDocument doc = new PDDocument();
            PDPage page = new PDPage();
            doc.addPage(page);

            PDPageContentStream content = new PDPageContentStream(doc, page);

            content.beginText();
            content.setFont(PDType1Font.TIMES_ROMAN, 26);
            content.moveTextPositionByAmount(220, 750);
            content.drawString("Titel");
            content.endText();

            content.beginText();
            content.setFont(PDType1Font.TIMES_ROMAN, 16);
            content.moveTextPositionByAmount(80, 700);
            content.drawString("Inhoud");
            content.endText();

            content.close();
            doc.save(fileName);
            doc.close();

            System.out.println("your file was saved in: " + System.getProperty("user.dir"));

        } catch (Exception e) {
            System.err.println(e.getMessage());
        }
    }

    @FXML
    public void openHome(ActionEvent event) throws IOException {
        Node node = (Node) event.getSource();
        final Stage stage = (Stage) node.getScene().getWindow();
        Parent root = FXMLLoader.load(getClass().getResource("/fxml/Homepage.fxml"));
        Scene scene = new Scene(root);
        stage.setScene(scene);
        stage.show();
        stage.centerOnScreen();

        final Parent home = FXMLLoader.load(getClass().getResource("/fxml/Homepage.fxml"));
        final Scene hScene = new Scene(home);
        root.setOnKeyPressed(new EventHandler<KeyEvent>() {
            public void handle(KeyEvent ke) {
                if (ke.getCode() == KeyCode.ESCAPE) {
                    System.out.println("Key Pressed: " + ke.getCode() + " Made by ShaMaster");
                    stage.setScene(hScene);
                }
            }
        });
    }

}