import { ActionFormData } from "@minecraft/server-ui";

function showMainUI(player) {
    const ui = new ActionFormData()
        .title("recipebook.title")
        .body("recipebook.body")
        .button("recipebook.craftingTable")
        .button("recipebook.stove")
        .button("recipebook.furnace")
        .button("recipebook.fridge");

    ui.show(player).then(response => {
        if (response.canceled) return;

        switch (response.selection) {
            case 0:
                showDossierUI(player, "recipebook.craftingTable", "recipe.craftingTable");
                break;
            case 1:
                showDossierUI(player, "recipebook.stove", "recipe.stove");
                break;
            case 2:
                showDossierUI(player, "recipebook.furnace", "recipe.furnace");
                break;
            case 3:
                showDossierUI(player, "recipebook.fridge", "recipe.fridge");
                break;
        }
    });
}

function showDossierUI(player, title, dossier) {
    const ui = new ActionFormData()
        .title(title)
        .body(dossier)
        .button("button.back");

    ui.show(player).then(response => {
        if (response.canceled) return;
        showMainUI(player);
    });
}

globalThis.openCookbookUI = showMainUI;