// Path: src/main/java/com/redcanari/ui/JSLoginDialog.java
// public class JSLoginDialog extends Dialog<Pair<String, String>> {
// 
//     private final TextField username;
// 
//     public JSLoginDialog() {
//         setTitle("Login Dialog");
// 
//         // Set the icon (must be included in the project).
// //        setGraphic(new ImageView(this.getClass().getResource("login.png").toString()));
// 
//         // Set the button types.
//         ButtonType loginButtonType = new ButtonType("Login", ButtonBar.ButtonData.OK_DONE);
//         getDialogPane().getButtonTypes().addAll(loginButtonType, ButtonType.CANCEL);
// 
//         // Create the username and password labels and fields.
//         GridPane grid = new GridPane();
//         grid.setHgap(10);
//         grid.setVgap(10);
//         grid.setPadding(new Insets(20, 150, 10, 10));
// 
//         username = new TextField();
//         username.setPromptText("Username");
//         PasswordField password = new PasswordField();
//         password.setPromptText("Password");
// 
//         grid.add(new Label("Username:"), 0, 0);
//         grid.add(username, 1, 0);
//         grid.add(new Label("Password:"), 0, 1);
//         grid.add(password, 1, 1);
// 
//         // Enable/Disable login button depending on whether a username was entered.
//         Node loginButton = getDialogPane().lookupButton(loginButtonType);
// //        loginButton.setDisable(true);
// 
//         // Do some validation (using the Java 8 lambda syntax).
// //        username.textProperty().addListener((observable, oldValue, newValue) -> {
// //            loginButton.setDisable(newValue.trim().isEmpty());
// //        });
// 
//         getDialogPane().setContent(grid);
// 
//         // Convert the result to a username-password-pair when the login button is clicked.
//         setResultConverter(dialogButton -> {
//             if (dialogButton == loginButtonType) {
//                 return new Pair<>(username.getText(), password.getText());
//             }
//             return null;
//         });
//     }
// 
//     public Pair<String, String> login(String loginPrompt) {
//         // Set the masthead to the user's prompt message.
//         setHeaderText(loginPrompt);
// 
//         // Request focus on the textfield so the user can type their response right away.
//         // Request focus on the username field by default.
//         Platform.runLater(username::requestFocus);
// 
//         // Show and wait for the result and then return a string or null
//         Optional<Pair<String, String>> result = super.showAndWait();
//         return (result.isPresent())?result.get():null;
//     }
// }
// 
// Path: src/main/java/com/redcanari/util/ResourceUtils.java
// public class ResourceUtils {
// 
//     public static String getResourceContentsAsString(String filename) {
//         InputStream inputStream = ResourceUtils.class.getResourceAsStream(filename);
//         return new Scanner(inputStream).useDelimiter("\\Z").next();
//     }
// }


import com.redcanari.ui.JSInputDialog;
import com.redcanari.ui.JSLoginDialog;
import com.redcanari.util.ResourceUtils;
import javafx.application.Platform;
import javafx.scene.web.PromptData;
import javafx.scene.web.WebEngine;
import javafx.stage.FileChooser;
import javafx.util.Pair;
import netscape.javascript.JSObject;
import javax.swing.*;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.net.URLConnection;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.nio.file.StandardOpenOption;
import java.util.List;
import java.util.Optional;
        return (file == null)?null:file.toString();
    }

    public String openFileDialog(String title) {
        FileChooser fileChooser = new FileChooser();
        fileChooser.setTitle(title);
        File file = fileChooser.showOpenDialog(null);
        return (file == null)?null:file.toString();
    }

    public JSObject openMultipleDialog(String title) {
        FileChooser fileChooser = new FileChooser();
        fileChooser.setTitle(title);
        List<File> files = fileChooser.showOpenMultipleDialog(null);
        return (files == null)? (JSObject) webEngine.executeScript("new Array") :Helpers.toJSArray(webEngine, files);
    }

    public void writeToFile(String file, String data) throws IOException {
        Files.write(new File(file).toPath(), data.getBytes(), StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING);
    }

    public String readFromFile(String file) throws IOException {
        return new String(Files.readAllBytes(new File(file).toPath()));
    }

    public void appendToFile(String file, String data) throws IOException {
        Files.write(new File(file).toPath(), data.getBytes(), StandardOpenOption.APPEND, StandardOpenOption.CREATE);
    }

    public void loginPrompt(JSObject callback) {
// Path: src/main/java/com/redcanari/ui/JSLoginDialog.java
// public class JSLoginDialog extends Dialog<Pair<String, String>> {
// 
//     private final TextField username;
// 
//     public JSLoginDialog() {
//         setTitle("Login Dialog");
// 
//         // Set the icon (must be included in the project).
// //        setGraphic(new ImageView(this.getClass().getResource("login.png").toString()));
// 
//         // Set the button types.
//         ButtonType loginButtonType = new ButtonType("Login", ButtonBar.ButtonData.OK_DONE);
//         getDialogPane().getButtonTypes().addAll(loginButtonType, ButtonType.CANCEL);
// 
//         // Create the username and password labels and fields.
//         GridPane grid = new GridPane();
//         grid.setHgap(10);
//         grid.setVgap(10);
//         grid.setPadding(new Insets(20, 150, 10, 10));
// 
//         username = new TextField();
//         username.setPromptText("Username");
//         PasswordField password = new PasswordField();
//         password.setPromptText("Password");
// 
//         grid.add(new Label("Username:"), 0, 0);
//         grid.add(username, 1, 0);
//         grid.add(new Label("Password:"), 0, 1);
//         grid.add(password, 1, 1);
// 
//         // Enable/Disable login button depending on whether a username was entered.
//         Node loginButton = getDialogPane().lookupButton(loginButtonType);
// //        loginButton.setDisable(true);
// 
//         // Do some validation (using the Java 8 lambda syntax).
// //        username.textProperty().addListener((observable, oldValue, newValue) -> {
// //            loginButton.setDisable(newValue.trim().isEmpty());
// //        });
// 
//         getDialogPane().setContent(grid);
// 
//         // Convert the result to a username-password-pair when the login button is clicked.
//         setResultConverter(dialogButton -> {
//             if (dialogButton == loginButtonType) {
//                 return new Pair<>(username.getText(), password.getText());
//             }
//             return null;
//         });
//     }
// 
//     public Pair<String, String> login(String loginPrompt) {
//         // Set the masthead to the user's prompt message.
//         setHeaderText(loginPrompt);
// 
//         // Request focus on the textfield so the user can type their response right away.
//         // Request focus on the username field by default.
//         Platform.runLater(username::requestFocus);
// 
//         // Show and wait for the result and then return a string or null
//         Optional<Pair<String, String>> result = super.showAndWait();
//         return (result.isPresent())?result.get():null;
//     }
// }
// 
// Path: src/main/java/com/redcanari/util/ResourceUtils.java
// public class ResourceUtils {
// 
//     public static String getResourceContentsAsString(String filename) {
//         InputStream inputStream = ResourceUtils.class.getResourceAsStream(filename);
//         return new Scanner(inputStream).useDelimiter("\\Z").next();
//     }
// }


// Path: src/main/java/com/redcanari/js/BurpKitBridge.java
import com.redcanari.ui.JSInputDialog;
import com.redcanari.ui.JSLoginDialog;
import com.redcanari.util.ResourceUtils;
import javafx.application.Platform;
import javafx.scene.web.PromptData;
import javafx.scene.web.WebEngine;
import javafx.stage.FileChooser;
import javafx.util.Pair;
import netscape.javascript.JSObject;
import javax.swing.*;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.net.URLConnection;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.nio.file.StandardOpenOption;
import java.util.List;
import java.util.Optional;

        return (file == null)?null:file.toString();
    }

    public String openFileDialog(String title) {
        FileChooser fileChooser = new FileChooser();
        fileChooser.setTitle(title);
        File file = fileChooser.showOpenDialog(null);
        return (file == null)?null:file.toString();
    }

    public JSObject openMultipleDialog(String title) {
        FileChooser fileChooser = new FileChooser();
        fileChooser.setTitle(title);
        List<File> files = fileChooser.showOpenMultipleDialog(null);
        return (files == null)? (JSObject) webEngine.executeScript("new Array") :Helpers.toJSArray(webEngine, files);
    }

    public void writeToFile(String file, String data) throws IOException {
        Files.write(new File(file).toPath(), data.getBytes(), StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING);
    }

    public String readFromFile(String file) throws IOException {
        return new String(Files.readAllBytes(new File(file).toPath()));
    }

    public void appendToFile(String file, String data) throws IOException {
        Files.write(new File(file).toPath(), data.getBytes(), StandardOpenOption.APPEND, StandardOpenOption.CREATE);
    }

    public void loginPrompt(JSObject callback) {
        Pair<String, String> result = new JSLoginDialog().login("Login");