package controllers;

import javafx.fxml.FXML;
import javafx.scene.Parent;
import javafx.scene.control.Label;
import javafx.scene.layout.GridPane;
import model.SceneCode;

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

/**
 * Created by Gondr on 4/04/2017.
 */
public class BaseController extends Controller {

    @FXML
    GridPane base;
    @FXML
    Label loggedInAs;

    private int childNum = 0;//number of children before appending

    public void addRide() throws Exception {
        changeScene(SceneCode.ADD_RIDE);
    }

    public void myRides() throws Exception{
        changeScene(SceneCode.MY_RIDES);
    }

    public void addStops() throws Exception {
        changeScene(SceneCode.ADD_STOPS);
    }

    public void myStops() throws Exception{
        changeScene(SceneCode.MY_STOPS);
    }

    public void searchStops() throws Exception{
        changeScene(SceneCode.SEARCH_STOPS);
    }

    public void addRoute() throws Exception{
        changeScene(SceneCode.ADD_ROUTE);
    }

    public void myRoutes() throws Exception{
        changeScene(SceneCode.MY_ROUTES);
    }

    public void addTrip() throws Exception{
        changeScene(SceneCode.ADD_TRIP);
    }

    public void myTrips() throws Exception{
        changeScene(SceneCode.MY_TRIPS);
    }

    public void shareRide() throws Exception{
        changeScene(SceneCode.MY_TRIPS);
    }

    public void sharedRides() throws Exception{
        changeScene(SceneCode.SHARED_RIDES);
    }

    public void setContent(Parent parent1){
        //remove all children that do not belong to the original fxml
        while (base.getChildren().size() > childNum) {
            base.getChildren().remove(base.getChildren().size() - 1);
        }
        base.add(parent1, 1, 0);
        loggedInAs.setText(String.format("Logged in as %s", parent.getSession().getUserCode()));
    }

    public void logout() throws Exception {
        changeScene(SceneCode.MAIN);
    }

    @Override
    public void initialize(URL location, ResourceBundle resources) {
        childNum = base.getChildren().size();
    }
}
