package app.service;

import java.io.File;

import app.model.Model;
import javafx.scene.control.Alert;
import javafx.scene.control.Alert.AlertType;
import javafx.stage.DirectoryChooser;
import javafx.stage.FileChooser;
import javafx.stage.Stage;

public class DialogBoxes {

  private DialogBoxes() {}
  private static FileChooser fc = new FileChooser();
  private static DirectoryChooser dc = new DirectoryChooser();
  private static Alert error = new Alert(AlertType.ERROR);

  public static void showErrorMessage(String errorMessage) {
      error.setContentText(errorMessage);
      error.showAndWait();
  }

  public static File showopenFileWithDialog(Stage stage) {
    fc.setTitle("Open File");
    File chosenFile = fc.showOpenDialog(stage);

    return chosenFile; 
  }

  public static File showOpenFolderWithDialog(Stage stage) {
    dc.setTitle("Open Project");
    File dir = dc.showDialog(stage);

    return dir;
  }

  public static File showSaveFileWithDialog(Stage stage) {
    FileChooser fc = new FileChooser();
    fc.setTitle("Save as");

    Model
      .getProjectPath()
      .ifPresent(path -> fc.setInitialDirectory(path.toFile()));

    File chosenLocation = fc.showSaveDialog(stage);

    return chosenLocation;
  }
  
}
