package ch.zhaw.prog2.application;

import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.Label;
import javafx.scene.control.TextArea;
import javafx.scene.control.TextField;

import java.util.Locale;

public class MainWindowController {


    WordModelDecorator wordModelDecorator;

	public void initialize(){
		connectProperties();
	}

	@FXML
	private Label labelTitel;

	@FXML
	private TextField textEingabe;

	@FXML
	private TextArea textHistory;

	@FXML
	void hinzufuegenText(ActionEvent event) {
        String[] text = textEingabe.getText().toLowerCase().split(" ");
        for(String word : text) {
	    	wordModelDecorator.addWord(word);
	    }
    }

	@FXML
	void leerenTextEingabe(ActionEvent event) {
		textEingabe.clear();
	}

    void setWordModel(WordModel wordModel){
        wordModelDecorator = new WordModelDecorator(wordModel);
        wordModelDecorator.addListener(new IsObserver() {
            @Override
            public void update() {
                textHistory.setText(wordModel.toString());
            }
        });
    }

	void connectProperties() {
		// erste Möglichkeit
		labelTitel.textProperty().bind(textEingabe.textProperty());
	}

}
