/**
   * Adds a "grass" component to the map, aka a null component Useful if the user wants to delete a
   * map component they placed in the map
   *
   * @param x the x coordinate where to add the grass
   * @param y the y coordinate where to add the grass
   * @param map the map to add the grass to
   * @param mapGridGUIDecorator the GUI decorator associated with this map
   * @param mapGridPane the gridPane that would need to be updated with the new view
   * @param imgView the associated image to place in the x,y cell
   */
  private void addGrass(
      int x,
      int y,
      Map map,
      MapGridGUIDecorator mapGridGUIDecorator,
      GridPane mapGridPane,
      ImageView imgView) {
    Coordinate coord = new Coordinate(x, y);
    map.clearCell(coord);

    StackPane sp = mapGridGUIDecorator.redrawCell(x, y, mapGridPane);

    sp.setOnMouseClicked(
        click -> {
          ComponentType currentFocused = MapMakerController.getCurrentFocused();
          if (currentFocused == ComponentType.INTERSECTION) {
            addIntersection(x, y, map, mapGridGUIDecorator, mapGridPane, intersectionImgView);
          } else if (currentFocused == ComponentType.ROADNS) {
            addRoadNS(x, y, map, mapGridGUIDecorator, mapGridPane, roadNSImgView);
          } else if (currentFocused == ComponentType.ROADEW) {
            addRoadEW(x, y, map, mapGridGUIDecorator, mapGridPane, roadEWImgView);
          }
        });

    // put focus back on Grass
    MapMakerController.setPreviousFocused(MapMakerController.getCurrentFocused());
    MapMakerController.setCurrentFocused(ComponentType.GRASS);
    imgView.requestFocus();
  }
  /**
   * Adds a section of road with 2 lanes that travels in the directions east and west
   *
   * @param x the x coordinate where to add the road
   * @param y the y coordinate where to add the road
   * @param map the map to add the road to
   * @param mapGridGUIDecorator the GUI decorator associated with this map
   * @param mapGridPane the gridPane that would need to be updated with the new view
   * @param imgView the associated image to place in the x,y cell
   */
  private void addRoadEW(
      int x,
      int y,
      Map map,
      MapGridGUIDecorator mapGridGUIDecorator,
      GridPane mapGridPane,
      ImageView imgView) {
    Coordinate coord = new Coordinate(x, y);
    Road road = new Road(coord, coord);
    try {
      road.addLane(new Lane(coord, coord, MapDirection.EAST));
      road.addLane(new Lane(coord, coord, MapDirection.WEST));
      map.addRoad(road);
      StackPane sp = mapGridGUIDecorator.redrawCell(x, y, mapGridPane);

      sp.setOnMouseClicked(
          click -> {
            ComponentType currentFocused = MapMakerController.getCurrentFocused();
            if (currentFocused == ComponentType.INTERSECTION) {
              addIntersection(x, y, map, mapGridGUIDecorator, mapGridPane, intersectionImgView);
            } else if (currentFocused == ComponentType.ROADNS) {
              addRoadNS(x, y, map, mapGridGUIDecorator, mapGridPane, roadNSImgView);
            } else if (currentFocused == ComponentType.GRASS) {
              addGrass(x, y, map, mapGridGUIDecorator, mapGridPane, grassImgView);
            }
          });

      // put focus back on RoadEW
      MapMakerController.setPreviousFocused(MapMakerController.getCurrentFocused());
      MapMakerController.setCurrentFocused(ComponentType.ROADEW);
      imgView.requestFocus();
    } catch (Exception e) {
      e.printStackTrace();
    }
  }