package GUI;

import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
import javafx.stage.StageStyle;
import model.SOMLayout;
import workers.FilesWorker;

/**
 * Created by Simon on 13.06.2016.
 */
public class SOMGUI extends Application {


    //    picture
    //    gallery
    //    upload
    //    capture
    //    warn

    // CONTROLLER
    public static PictureCtl pictureCtl;
    public static GalleryCtl galleryCtl;
    public static UploadCtl uploadCtl;
    public static CaptureCtl captureCtl;
    public static WarnCtl warnCtl;
    // STAGE
    private static Stage thestage;
    // PANES
    private static Parent picture;
    private static Parent gallery;
    private static Parent upload;
    private static Parent capture;
    private static Parent warn;
    //SCENES
    private static Scene pictureScene;
    private static Scene galleryScene;
    private static Scene uploadScene;
    private static Scene captureScene;
    private static Scene warnScene;
    // INSTANCE
    private static SOMGUI somgui;

    protected SOMGUI() throws Exception {
        // set up the scenes
        FXMLLoader pictureLoader = new FXMLLoader(getClass().getResource("/fxml/picture.fxml"));
        picture = pictureLoader.load();
        pictureCtl = pictureLoader.getController();

        FXMLLoader galleryLoader = new FXMLLoader(getClass().getResource("/fxml/gallery.fxml"));
        gallery = galleryLoader.load();
        galleryCtl = galleryLoader.getController();

        FXMLLoader uploadLoader = new FXMLLoader(getClass().getResource("/fxml/upload.fxml"));
        upload = uploadLoader.load();
        uploadCtl = uploadLoader.getController();

        FXMLLoader captureLoader = new FXMLLoader(getClass().getResource("/fxml/capture.fxml"));
        capture = captureLoader.load();
        captureCtl = captureLoader.getController();

        FXMLLoader warnLoader = new FXMLLoader(getClass().getResource("/fxml/warn.fxml"));
        warn = warnLoader.load();
        warnCtl = warnLoader.getController();

        // Initialize the Scenes
        pictureScene = new Scene(picture, SOMLayout.screenWidth, SOMLayout.screenHeight);
        galleryScene = new Scene(gallery, SOMLayout.screenWidth, SOMLayout.screenHeight);
        uploadScene = new Scene(upload, SOMLayout.screenWidth, SOMLayout.screenHeight);
        captureScene = new Scene(capture, SOMLayout.screenWidth, SOMLayout.screenHeight);
        warnScene = new Scene(warn, SOMLayout.screenWidth, SOMLayout.screenHeight);
    }

    public static SOMGUI getInstance() throws Exception {
        if (somgui == null) {
            somgui = new SOMGUI();
        }
        return somgui;
    }

    public static void changetopicture() {
        thestage.setScene(pictureScene);
    }

    public static void changetogallery() {
        thestage.setScene(galleryScene);
    }

    public static void changetoupload() {
        thestage.setScene(uploadScene);
    }

    public static void changetocapture() {
        thestage.setScene(captureScene);
    }

    public static void changetowarn() {
        thestage.setScene(warnScene);
    }

    @Override
    public void start(Stage primaryStage) throws Exception {
        // make the Stage Accessible
        thestage = primaryStage;

        // remove all borders
        thestage.initStyle(StageStyle.UNDECORATED);
        // set stage to fullscreen
        thestage.setFullScreen(true);
        // set the upper left X & Y position of the stage
        thestage.setX(0);
        thestage.setY(0);

        // set stage visible
        thestage.show();

        // Set the Upload scene
        changetoupload();
        // Start Upload Process
        FilesWorker.upload();
        // Set the Picture scene
    }
}