package visualiser.Controllers;

import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.scene.control.Label;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import visualiser.model.VisualiserBoat;

/**
 * Finish Screen for when the race finishes.
 */
public class RaceFinishController extends Controller {
    private @FXML TableView<VisualiserBoat> boatInfoTable;
    private @FXML TableColumn<VisualiserBoat, String> boatRankColumn;
    private @FXML TableColumn<VisualiserBoat, String> boatNameColumn;
    private @FXML Label raceWinnerLabel;

    /**
     * Display the table
     * @param boats boats to display on the table.
     */
    public void loadFinish(ObservableList<VisualiserBoat> boats) {
        // set table contents
        boatInfoTable.setItems(boats);
        //Name.
        boatNameColumn.setCellValueFactory(cellData -> cellData.getValue().nameProperty());
        //Rank/position.
        boatRankColumn.setCellValueFactory(cellData -> cellData.getValue().placingProperty());

        //Winner label.
        if (boats.size() > 0) {
            raceWinnerLabel.setText("Winner: " +
                    boatNameColumn.getCellObservableValue(0).getValue());
            raceWinnerLabel.setWrapText(true);
        }
    }

}
