package controllers;

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

import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;
import javafx.scene.control.DatePicker;
import javafx.scene.control.ScrollPane;
import javafx.scene.layout.FlowPane;
import objects.UpdateRaceRow;

public class UpdateTabController implements Initializable {

	@FXML FlowPane flowPaneRowContainer;
	@FXML Button getRacesButton;
	@FXML DatePicker datePicker;
	@FXML ScrollPane RacesTable;

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


	@FXML void getRacesAction() {
		final List<UpdateRaceRow> racesToUpdate = DatabaseController.getInstance().getRacesToUpdate(datePicker.getValue().toString());

		flowPaneRowContainer.getChildren().clear();
		if (flowPaneRowContainer.getChildren().size() < 1) {
			final UpdateRaceRow header = new UpdateRaceRow(0, "RaceDate", "RaceType", false, 0, "Track Name", 0);
			flowPaneRowContainer.getChildren().add(header.getGui(true));
		}
		for (final UpdateRaceRow updateRaceRow : racesToUpdate) {
			flowPaneRowContainer.getChildren().add(updateRaceRow.getGui(false));
		}

	}
}
