package objects;

import javafx.collections.ObservableList;
import javafx.scene.Node;
import javafx.scene.control.TextField;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Pane;

public class BongObject extends HBox {

    int lane;
    String horse;
    String driver;
    int raceNumber;

    HBox content;
    private final Pane raceNumberPane;
    private final Pane horsePane;
    private final Pane driverPane;
    private final Pane lanePane;

    BongObject() {
        content = new HBox();

        raceNumberPane = new Pane();
        driverPane = new Pane();
        horsePane = new Pane();
        lanePane = new Pane();

        raceNumberPane.getChildren().add(new TextField());
        horsePane.getChildren().add(new TextField());
        driverPane.getChildren().add(new TextField());
        lanePane.getChildren().add(new TextField());

        final ObservableList<Node> children = content.getChildren();
        children.add(raceNumberPane);
        children.add(horsePane);
        children.add(driverPane);
        children.add(lanePane);
    }

    public HBox getContent() {
        return content;
    }

    public int getLane() {
        return lane;
    }

    public String getHorse() {
        return horse;
    }

    public String getDriver() {
        return driver;
    }

    public void addLane(int lane) {
        this.lane = lane;
        final TextField laneText = (TextField) lanePane.getChildren().get(0);
        String text = laneText.getText();
        if (text.length() > 0) {
            text += ", " + lane;
        } else {
            text = String.valueOf(lane);
        }
        laneText.setText(text);
    }

    public void addHorse(String horse) {
        this.horse = horse;
        final TextField horseText = (TextField) horsePane.getChildren().get(0);
        String text = horseText.getText();
        if (text.length() > 0) {
            text += ", " + horse;
        } else {
            text = horse;
        }
        horseText.setText(text);
    }

    public void addDriver(String driver) {
        this.driver = driver;
        final TextField driverText = (TextField) driverPane.getChildren().get(0);
        String text = driverText.getText();
        if (text.length() > 0) {
            text += ", " + driver;
        } else {
            text = driver;
        }
        driverText.setText(text);
    }

    public int getRaceNumber() {
        return raceNumber;
    }

    public void setRaceNumber(int raceNumber) {
        this.raceNumber = raceNumber;
        ((TextField) raceNumberPane.getChildren().get(0)).setText(String.valueOf(raceNumber));
    }

}
