package controllers;

import java.net.URL;
import java.util.List;
import java.util.ResourceBundle;

import controllers.NewTab.MainContent;
import javafx.application.Platform;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;
import javafx.scene.control.DatePicker;
import objects.HorseRaceData;

public class NewTabController implements Initializable {

    @FXML Button submitButton;
    @FXML DatePicker datePicker;


    @Override
    public void initialize(URL arg0, ResourceBundle arg1) {

        datePicker.valueProperty().addListener((observable, oldValue, newValue) -> {
            if (newValue == null) {
                submitButton.setDisable(true);
            } else {
                submitButton.setDisable(false);
            }
        });

    }


    @FXML
    public void submitAction() {
        submitButton.setDisable(true);

        Platform.runLater(() -> {
            final List<HorseRaceData> todaysRaces = DatabaseController.getInstance().getRacesFromDate(datePicker.getValue().toString(), false);

            MainContent.getThis().updateRaceTable(todaysRaces);

            submitButton.setDisable(false);
        });
    }
}
