import * as ui from "@minecraft/server-ui";

const SOUND_TURN_PAGE = "item.book.page_turn";
const SOUND_OPTIONS = { pitch: 1.0, volume: 1.0, };

const MENU_MAIN = new ui.ActionFormData();
const MENU_FOOD = new ui.ActionFormData();
const MENU_GEAR = new ui.ActionFormData();
const MENU_MOBS = new ui.ActionFormData();
const MENU_TENTS = new ui.ActionFormData();
const MENU_RECIPE = new ui.ActionFormData();

export function setupStaticMenus() {
    //BOOK MAIN
    MENU_MAIN.title({ translate: "nn_camp_menu_main_title" });
    MENU_MAIN.body({ translate: "nn_camp_menu_main_body", "with": ["\n"] });
    MENU_MAIN.button({ translate: "nn_camp_menu_button_tent" }, "textures/captainsparklez/nn_camp/items/campingtent_green");
    MENU_MAIN.button({ translate: "nn_camp_menu_button_food" }, "textures/captainsparklez/nn_camp/items/smore_welldone");
    MENU_MAIN.button({ translate: "nn_camp_menu_button_gear" }, "textures/captainsparklez/nn_camp/items/camp_torch");
    MENU_MAIN.button({ translate: "nn_camp_menu_button_mobs" }, "textures/captainsparklez/nn_camp/items/fairy_dust");
    MENU_MAIN.button({ translate: "nn_camp_menu_button_recipes" }, "textures/captainsparklez/nn_camp/items/batteries");

    MENU_TENTS.title({ translate: "nn_camp_menu_tent_title" });
    MENU_TENTS.body({ translate: "nn_camp_menu_tent_body", "with": ["\n"] });
    MENU_TENTS.button({ translate: "nn_camp_menu_button_main" }, "textures/captainsparklez/nn_camp/items/guildbook");
    
    MENU_FOOD.title({ translate: "nn_camp_menu_food_title" });
    MENU_FOOD.body({ translate: "nn_camp_menu_food_body", "with": ["\n"] });
    MENU_FOOD.button({ translate: "nn_camp_menu_button_main" }, "textures/captainsparklez/nn_camp/items/guildbook");
    
    MENU_GEAR.title({ translate: "nn_camp_menu_gear_title" });
    MENU_GEAR.body({ translate: "nn_camp_menu_gear_body", "with": ["\n"] });
    MENU_GEAR.button({ translate: "nn_camp_menu_button_main" }, "textures/captainsparklez/nn_camp/items/guildbook");
    
    MENU_MOBS.title({ translate: "nn_camp_menu_mobs_title" });
    MENU_MOBS.body({ translate: "nn_camp_menu_mobs_body", "with": ["\n"] });
    MENU_MOBS.button({ translate: "nn_camp_menu_button_main" }, "textures/captainsparklez/nn_camp/items/guildbook");

    MENU_RECIPE.title({ translate: "nn_camp_menu_recipes_title" });
    MENU_RECIPE.body({ translate: "nn_camp_menu_recipes_body", "with": ["\n"] });
    MENU_RECIPE.button({ translate: "nn_camp_menu_button_main" }, "textures/captainsparklez/nn_camp/items/guildbook");

}

export function menuMain(player) {
    player.playSound(SOUND_TURN_PAGE, SOUND_OPTIONS);
    MENU_MAIN.show(player).then(result => {
        if (result.canceled) return;
        let response = result.selection;
        switch (response) {
            case 0:
                menuTents(player);
                break;
            case 1:
                menuFood(player);
                break;
            case 2:
                menuGear(player);
                break; 
            case 3:
                menuMobs(player);  
                break;
            case 4:
                menuRecipes(player);  
                break;    
            default: break;
        }
    });
}

function menuTents(player) {
    player.playSound(SOUND_TURN_PAGE, SOUND_OPTIONS);
    MENU_TENTS.show(player).then(result => {
        if (result.canceled) return;
        let response = result.selection;
        switch (response) {
            case 0:
                menuMain(player);
                break;
            default: break;
        }
    });
}

function menuRecipes(player) {
    player.playSound(SOUND_TURN_PAGE, SOUND_OPTIONS);
    MENU_RECIPE.show(player).then(result => {
        if (result.canceled) return;
        let response = result.selection;
        switch (response) {
            case 0:
                menuMain(player);
                break;
            default: break;
        }
    });
}

function menuFood(player) {
    player.playSound(SOUND_TURN_PAGE, SOUND_OPTIONS);
    MENU_FOOD.show(player).then(result => {
        if (result.canceled) return;
        let response = result.selection;
        switch (response) {
            case 0:
                menuMain(player);
                break;
            default: break;
        }
    });
}

function menuGear(player) {
    player.playSound(SOUND_TURN_PAGE, SOUND_OPTIONS);
    MENU_GEAR.show(player).then(result => {
        if (result.canceled) return;
        let response = result.selection;
        switch (response) {
            case 0:
                menuMain(player);
                break;
            default: break;
        }
    });
}

function menuMobs(player) {
    player.playSound(SOUND_TURN_PAGE, SOUND_OPTIONS);
    MENU_MOBS.show(player).then(result => {
        if (result.canceled) return;
        let response = result.selection;
        switch (response) {
            case 0:
                menuMain(player);
                break;
            default: break;
        }
    });
}