package fabrik.simulator.pic16f84;

import fabrik.simulator.pic16f84.interfaces.*;
import javafx.application.Application;

import javafx.fxml.FXMLLoader;
import javafx.scene.Node;
import javafx.scene.Parent;
import javafx.scene.Scene;

import javafx.scene.control.Tab;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;

import java.io.IOException;
import java.util.Objects;

public class CreateWindow extends Application {
    private PICComponents picComponents = new PICComponents(); // Subjekt
    public static GridPane grid = new GridPane();
    private static VBox table;

    @Override
    public void start(Stage primaryStage) throws IOException {

        picComponents.registerComponent(CommandInterface.class, new Commands());
        picComponents.registerComponent(ToggleButtonInterface.class, new ToggleButtonGroupExt());
        picComponents.registerComponent(FrontendControllerInterface.class, new Controller_Frontend());
        picComponents.registerComponent(DataRegisterInterface.class, new DataRegister());
        picComponents.registerComponent(EEPROMInterface.class, new EEPROM());
        picComponents.registerComponent(InterruptInterface.class, new Interrupts());
        picComponents.registerComponent(IOPortInterface.class, new IOPorts());
        picComponents.registerComponent(PreScalerInterface.class, new PreScaler());
        picComponents.registerComponent(ProgramStackInterface.class, new ProgramStack());
        picComponents.registerComponent(TimerInterface.class, new Timer());
        picComponents.registerComponent(WatchdogTimerInterface.class, new WatchdogTimer());
        picComponents.initAll();

        FXMLLoader codewindow = new FXMLLoader(CreateWindow.class.getResource("frontend.fxml"));
        codewindow.setController(picComponents.getComponent(FrontendControllerInterface.class));
        Parent code = codewindow.load();
        table = Table.init(picComponents);
        grid.add(table, 1, 1);
        grid.add(code, 0, 1);

        grid.relocate(0, 0);

        grid.getStylesheets().add(Objects.requireNonNull(getClass().getResource("styles.css")).toExternalForm());
        Scene scene = new Scene(grid, 1845, 800);
        primaryStage.setScene(scene);
        primaryStage.setTitle("Simulator");
        primaryStage.show();
    }

    public static void main(String[] args) {
        launch(args);
    }

    public static void refreshTable() {
        grid.getChildren().remove(table);
        table= Table.refresh();
        grid.add(table, 1, 1);
    }
}



