package ch.zhaw.gartenverwaltung;

import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;

/**
 * Controller class for the TexFieldFormular.fxml file
 */
public class TextFieldFormularController {

    @FXML
    private Label description_label;

    @FXML
    private TextField text_area;


    /**
     * set description label
     * @param string string of the description
     */
    public void setDescription_label(String string) {
        description_label.setText(string);
    }

    /**
     * set text area value
     * @param string string of text area value
     */
    public void setValueTextArea(String string) {
        text_area.setText(string);
    }

    /**
     * return value of text area
     * @return string of the tex area
     */
    public String getValue() {
        return text_area.getText();
    }

    /**
     * Disable Button until condition meet
     * @param button {@link Button} which is gets dissabled
     */
    public void initSaveButton(Button button) {
        text_area.textProperty().addListener((observable, oldValue, newValue) -> {
            if (newValue.matches("\\d*\\.?\\d*")) {
                text_area.setText(newValue);
            } else {
                text_area.setText(oldValue);
            }
        });

        button.disableProperty().bind(text_area.textProperty().isEmpty());
    }

}
