import {
  world, Player, ItemComponentTypes, ItemStack
} from '@minecraft/server';
import {
  ActionFormData
} from '@minecraft/server-ui';

function playMenuSound(player) {
    player.runCommandAsync(`playsound kaiju.menu_click @s`);
}

function look(player) {
    const profile = new ActionFormData()
        .title("§lKaiju Craft Info")
        .body("List Of Creator\n\nGojidraw\n\nBeef\n\n§4WARNING§f§lKaiju In The Add-on Will Cost A Lot Of Damage\nTo Your Minecraft World\n\n\nList of stats info of all The Kaiju + mob")
        .button("§L§bWARDENZILLA","textures/entity/wardenzilla/gojidraw_sculk_zilla_profile")
        .button("§L§eGOLEM KONG","textures/entity/golem_kong/gojidraw_golem_kong_profile")
        .button("§L§aROPHAN","textures/entity/rophantom/gojidraw_rophantom_profile")
        .button("§L§6BEHEMOOHOGLIN","textures/entity/behemoohoglin/gojidraw_behemoohoglin_profile")
        .button("§L§2SNIFFELAH","textures/entity/sniffelah/gojidraw_sniffelah_profile")
        .button("§L§bMOTHLLEY","textures/entity/mothlley/gojidraw_mothlley_profile")
        .button("§L§dWITHER GHIDORAH","textures/entity/wither_ghidorah/gojidraw_wither_ghidorah_profile")
        .button("§L§eBLAZING WARBAT","textures/entity/blazing_neakri/gojidraw_blazing_neakri_profile")
        .button("§L§1SQUCYLLA","textures/entity/squcylla/gojidraw_squcylla_profile")
        .button("§L§dFEMALE ENDER MUTO","textures/entity/ender_muto/gojidraw_ender_muto_female_profile")
        .button("§L§dMALE ENDER MUTO","textures/entity/ender_muto/gojidraw_ender_muto_male_profile")
        .button("§L§eBone Crawler","textures/entity/bone_crawler/gojidraw_bone_crawler_profile")
        .button("§L§4REDSTONEZILLA","textures/entity/mecha_wardenzilla/gojidraw_mecha_wardenzilla_profile")
        .show(player).then((e) => {
            playMenuSound(player);
            if (e.canceled) return; // Prevent errors if the player cancels the menu
            switch (e.selection) {
                case 0: profile1(player); break;
                case 1: profile2(player); break;
                case 2: profile3(player); break;
                case 3: profile4(player); break;
                case 4: profile5(player); break;
                case 5: profile6(player); break;
                case 6: profile7(player); break;
                case 7: profile8(player); break;
                case 8: profile9(player); break;
                case 9: profile10(player); break;
                case 10: profile11(player); break;
                case 11: profile12(player); break;
                case 12: profile13(player); break;
            }
        });
}

function createProfile(title, body, player) {
    const form = new ActionFormData()
        .title(title)
        .body(body)
        .button("§LBACK")
        .show(player).then((e) => {
            playMenuSound(player);
            if (e.selection === 0) look(player);
        });
}

function profile1(player) { createProfile("§bWARDENZILLA", "WARDENZILLA\n\n§e-HP =§f 7500\n§b-Melee =§f 150\n§f-Atomic Blast (per hit) =§f 125\n-Sonic roar =§f 300\n\n§f Behavior §4Hostile§f \n§f\n Category \nNeed a Warden DNA To Spawn", player); }
function profile2(player) { createProfile("§eGOLEM KONG", "GOLEM KONG\n\n§e-HP =§f 4500\n§b-Melee =§f 90\n\n§f Behavior §f§bNeutral§f \n§f\n Category \nNeed a Iron Golem DNA To Spawn", player); }
function profile3(player) { createProfile("§aROPHAN", "ROPHAN\n\n§e-HP =§f 3500\n§b-Melee =§f 75\n§a-Spin Attack (per hit) =§f 10\n§f-Soul Blast (per hit) =§f 40\n\n§f Behavior §f§4Hostile§f \n§f\n Category \nNeed a Phantom DNA To Spawn", player); }
function profile4(player) { createProfile("§6BEHEMOOHOGLIN", "BEHEMOOHOGLIN\n\n§e-HP =§f 5500\n§b-Melee =§f 85\n\n§f Behavior §f§bNeutral§f \n§f\n Category \nNeed a Hoglin DNA To Spawn", player); }
function profile5(player) { createProfile("§2SNIFFELAH", "SNIFFELAH\n\n§e-HP =§f 6500\n§b-Melee =§f 75\n\n§f Behavior §f§bNeutral§f \n§f\n Category \nNeed a Sniffer DNA To Spawn", player); }
function profile6(player) { createProfile("§bMOTHLLEY", "MOTHLLEY\n\n§e-HP =§f 2500\n§b-Melee =§f 75\n§a-Godray (per hit) =§f 45\n§f-Atomic Beam (per hit) =§f 75\n\n§f Behavior §f§bNeutral§f \n§f\n Category \nNeed a Alley DNA To Spawn", player); }
function profile7(player) { createProfile("§dWither Ghidorah", "WITHER GHIDORAH\n\n§e-HP =§f 30000\n§b-Melee =§f 350\n§f-Wither Gravity Beam (per hit) =§f 105\n-Roar =§f 600\n\n§f Behavior §4Hostile§f \n§f\n Category \nNeed a Wither DNA To Spawn", player); }
function profile8(player) { createProfile("§eBLAZING WARBAT", "BLAZING WARBAT\n\n§e-HP =§f 4000\n§b-Melee =§f 75\n§a-Roar =§f 150\n§f-Flame (per hit) =§f 40\n\n§f Behavior §4Hostile§f \n§f\n Category \nNeed a Blaze DNA To Spawn", player); }
function profile9(player) { createProfile("§1SQUCYLLA", "SQUCYLLA\n\n§e-HP =§f 3400\n§b-Melee =§f 95\n\n§f Behavior §f§4Hostile§f \n§f\n Category \nNeed a Squid And Spider DNA To Spawn", player); }
function profile10(player) { createProfile("§dFEMALE ENDER MUTO", "FEMALE ENDER MUTO\n\n§e-HP =§f 3000\n§b-Melee =§f 75\n\n§f Behavior §f§4Hostile§f \n§f\n Category \nNeed a Ender Mite DNA To Spawn", player); }
function profile11(player) { createProfile("§dMALE ENDER MUTO", "MALE ENDER MUTO\n\n§e-HP =§f 2000\n§b-Melee =§f 40\n\n§f Behavior §f§4Hostile§f \n§f\n Category \nNeed a Ender Mite And Bat DNA To Spawn", player); }
function profile12(player) { createProfile("§eBONE CRAWLER", "BONE CRAWLER MUTO\n\n§e-HP =§f 1500\n§b-Melee =§f 34\n\n§f Behavior §f§4Hostile§f \n§f\n Category \nNeed a Skeleton DNA To Spawn", player); }
function profile13(player) { createProfile("§4REDSTONEZILLA", "REDSTONEZILLA\n\n§e-HP =§f 7000\n§b-Melee =§f 200\n§f-Atomic Blast (per hit) =§f 150\n-Roar =§f 300\n\n§f Behavior §4Hostile§f \n§f\n Category \nNeed To Be Built Up To Spawn", player); }

world.afterEvents.itemUse.subscribe((event) => {
    const { source, itemStack } = event;
    if (itemStack?.typeId === "gojidraw:kaiju_stats_book") {
        playMenuSound(source);
        look(source);
    }
});