package de.wwwu.awolf.view.controller;

import de.wwwu.awolf.presenter.algorithms.Algorithm;
import de.wwwu.awolf.view.services.ButtonClickService;
import javafx.fxml.FXML;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.canvas.Canvas;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.VBox;
import javafx.scene.text.Font;

import java.util.Map;

public class AlgorithmTabController {

    private Algorithm.Type algorithmType;
    private Map<String, String> properties;

    @FXML
    public Canvas canvas;
    @FXML
    public VBox vBox;
    @FXML
    public Button startButton;



    public AlgorithmTabController() {

    }


    public void init() {
        // add GUI elements to maintain the parameters
        properties.forEach((key, value) -> {
            //Pane component for the layout
            BorderPane borderPane = new BorderPane();
            borderPane.setPadding(new Insets(10,0,10,0));

            //text field for the input
            TextField textField = new TextField(value);

            //label
            Label label = new Label(key);
            label.setAlignment(Pos.BASELINE_LEFT);
            label.setFont(new Font("Arial", 17));
            label.setLabelFor(textField);
            label.setPadding(new Insets(2,10,0,0));

            //add components
            borderPane.setLeft(label);
            borderPane.setRight(textField);
            vBox.getChildren().add(borderPane);
        });

        startButton.setOnAction(event -> {
            new ButtonClickService(algorithmType).start();
        });
    }

    public Algorithm.Type getAlgorithmType() {
        return algorithmType;
    }

    public void setAlgorithmType(Algorithm.Type algorithmType) {
        this.algorithmType = algorithmType;
    }

    public Map<String, String> getProperties() {
        return properties;
    }

    public void setProperties(Map<String, String> properties) {
        this.properties = properties;
    }
}
