import { Player, world } from '@minecraft/server';
import * as DynamicForms from '../utils/FormUtils';


/**
 *
 * @param {Player} player
*/
function loadGuidebookForm(player) {
    DynamicForms.actionForm(player, 'main', homePageData);
}


world.afterEvents.itemUse.subscribe((e) => {
    if (e.itemStack?.typeId !== 'ecbl_bc:guidebook') return;
    loadGuidebookForm(e.source);
})

const HowToData = [
{
    text: "guidebook_crafting", image: "textures/eternal/biome_craft/items/bc_guidebook",
}
];

const veldtlandsData = [
    {
        text: "veldtlands_blocks", image: 'textures/eternal/biome_craft/ui/category_blocks',
        subpages: [
            { text: "baobab_wood_set", image: 'textures/eternal/biome_craft/blocks/baobab_planks' },
            { text: "baobab_branch_blocks", image: 'textures/eternal/biome_craft/blocks/baobab_log_side' },
            { text: "ant_mound_blocks", image: 'textures/eternal/biome_craft/blocks/ant_mound' },
            { text: "quicksand", image: 'textures/eternal/biome_craft/blocks/quicksand' },
            { text: "glass_jar", image: 'textures/eternal/biome_craft/ui/glass_jar' },
            { text: "goldenrod_flower", image: 'textures/eternal/biome_craft/blocks/goldenrod_top' },
            { text: "dead_shrub", image: 'textures/eternal/biome_craft/items/dead_shrub' },
        ]
    },
    {
        text: "veldtlands_mobs", image: 'textures/eternal/biome_craft/ui/category_mobs',
        subpages: [
            { text: "lions", image: 'textures/eternal/biome_craft/ui/mobicon_lion' },
            { text: "elephants", image: 'textures/eternal/biome_craft/ui/mobicon_elephant' },
            { text: "vultures", image: 'textures/eternal/biome_craft/ui/mobicon_vulture' },
            { text: "ants", image: 'textures/eternal/biome_craft/ui/mobicon_ant' },
            { text: "zebras", image: 'textures/eternal/biome_craft/ui/mobicon_zebra' }
        ]
    },
    {
        text: "veldtlands_items", image: 'textures/eternal/biome_craft/ui/category_items',
        subpages: [
            { text: "prime_meat", image: 'textures/eternal/biome_craft/items/raw_prime_meat' },
            { text: "baobab_fruit", image: 'textures/eternal/biome_craft/items/baobab_fruit' },
            { text: "larva", image: 'textures/eternal/biome_craft/items/larva' },
            { text: "vulture_feather", image: 'textures/eternal/biome_craft/items/vulture_feather' },
            { text: "exoskeleton_armor", image: 'textures/eternal/biome_craft/items/exoskeleton_helmet' },
            { text: "bug_net", image: 'textures/eternal/biome_craft/items/empty_bug_net' },
            { text: "glider", image: 'textures/eternal/biome_craft/items/glider' },
            { text: "drum", image: 'textures/eternal/biome_craft/items/baobab_drumset' },
        ]
    }
];


const tropicalRainforestData = [
    {
        text: "tropical_rainforest_blocks", image: 'textures/eternal/biome_craft/ui/category_blocks',
        subpages: [
            { text: "kapok_wood_set", image: 'textures/eternal/biome_craft/blocks/kapok_planks' },
            { text: "heliconia_blooms", image: 'textures/eternal/biome_craft/items/heliconia' },
            { text: "orchid_blooms", image: 'textures/eternal/biome_craft/items/magenta_orchid' },
            { text: "monstera", image: 'textures/eternal/biome_craft/items/monstera' },
            { text: "giant_lilypads", image: 'textures/eternal/biome_craft/items/giant_lilypad' },
            { text: "lianas_climbing_vines", image: 'textures/eternal/biome_craft/blocks/climbing_vines' },
            { text: "kapok_tree_fern", image: 'textures/eternal/biome_craft/items/kapok_tree_fern' },
        ]
    },
    {
        text: "tropical_rainforest_mobs", image: 'textures/eternal/biome_craft/ui/category_mobs',
        subpages: [
            { text: "toucan", image: 'textures/eternal/biome_craft/ui/mobicon_toucan' },
            { text: "butterflies", image: 'textures/eternal/biome_craft/ui/mobicon_butterflies' },
            { text: "piranhas", image: 'textures/eternal/biome_craft/ui/mobicon_piranha' },
            { text: "jaguars", image: 'textures/eternal/biome_craft/ui/mobicon_jaguar' },
            { text: "pink_dolphin", image: 'textures/eternal/biome_craft/ui/mobicon_pinkdolphin' },
        ]
    },
    {
        text: "tropical_rainforest_items", image: 'textures/eternal/biome_craft/ui/category_items',
        subpages: [
            { text: "butterfly_wings", image: 'textures/eternal/biome_craft/items/b_yellowtail' },
            { text: "tropical_feathers", image: 'textures/eternal/biome_craft/items/tropical_feathers' },
            { text: "orchid_tea", image: 'textures/eternal/biome_craft/items/orchid_tea' },
            { text: "pan_flute", image: 'textures/eternal/biome_craft/items/pan_flute' },
        ]
    }
];

const redwoodForestData = [
    {
        text: "redwood_forest_blocks", image: 'textures/eternal/biome_craft/ui/category_blocks',
        subpages: [
            { text: "redwood_tree_set", image: 'textures/eternal/biome_craft/blocks/redwood_planks' },
            { text: "deadwood_stump", image: 'textures/eternal/biome_craft/blocks/deadwood_log_side' },
            { text: "redwood_tree_fern", image: 'textures/eternal/biome_craft/items/redwood_tree_fern' },
            { text: "bounce_mushrooms", image: 'textures/eternal/biome_craft/blocks/glowing_mush_block' },
            { text: "glowing_mushrooms", image: 'textures/eternal/biome_craft/blocks/glowing_mushroom' },
        ]
    },
    {
        text: "redwood_forest_mobs", image: 'textures/eternal/biome_craft/ui/category_mobs',
        subpages: [
            { text: "deer", image: 'textures/eternal/biome_craft/ui/mobicon_deer' },
            { text: "wolverines", image: 'textures/eternal/biome_craft/ui/mobicon_wolverine' },
            { text: "moose", image: 'textures/eternal/biome_craft/ui/mobicon_moose' },
            { text: "bears", image: 'textures/eternal/biome_craft/ui/mobicon_brownbear' },
            { text: "fireflies", image: 'textures/eternal/biome_craft/ui/mobicon_fireflies' },
        ]
    },
    {
        text: "redwood_forest_items", image: 'textures/eternal/biome_craft/ui/category_items',
        subpages: [
            { text: "antlers", image: 'textures/eternal/biome_craft/items/antler' },
            { text: "antlers_helmet", image: 'textures/eternal/biome_craft/items/antler_helmet' },
            { text: "fur", image: 'textures/eternal/biome_craft/items/fur' },
            { text: "fur_boots", image: 'textures/eternal/biome_craft/items/fur_boots' },
            { text: "bear_claw", image: 'textures/eternal/biome_craft/items/bear_claw' },
        ]
    }
];

const prairieData = [
    {
        text: "prairie_blocks", image: 'textures/eternal/biome_craft/ui/category_blocks',
        subpages: [
            { text: "pebbles", image: 'textures/eternal/biome_craft/items/pebbles' },
            { text: "corn", image: 'textures/eternal/biome_craft/blocks/corn_2_top' },
            { text: "tumbleweed", image: 'textures/eternal/biome_craft/blocks/dead_bush' },
            { text: "prickly_pear_cactus", image: 'textures/eternal/biome_craft/ui/prickly_pear' },
            { text: "cactus_bud", image: 'textures/eternal/biome_craft/items/cactus_bud' },
        ]
    },
    {
        text: "prairie_mobs", image: 'textures/eternal/biome_craft/ui/category_mobs',
        subpages: [
            { text: "bison", image: 'textures/eternal/biome_craft/ui/mobicon_bison' },
            { text: "eagles", image: 'textures/eternal/biome_craft/ui/mobicon_eagle' },
            { text: "ferrets", image: 'textures/eternal/biome_craft/ui/mobicon_ferret' },
            { text: "snakes", image: 'textures/eternal/biome_craft/ui/mobicon_snake' },
        ]
    },
    {
        text: "prairie_items", image: 'textures/eternal/biome_craft/ui/category_items',
        subpages: [
            { text: "eagle_talon", image: 'textures/eternal/biome_craft/items/eagle_talon' },
            { text: "talon_dagger", image: 'textures/eternal/biome_craft/items/talon_dagger' },
            { text: "venom_bottle", image: 'textures/eternal/biome_craft/items/venom_bottle' },
            { text: "slingshot", image: 'textures/eternal/biome_craft/items/slingshot' },
            { text: "prickly_pear_fruit", image: 'textures/eternal/biome_craft/items/prickly_pear_fruit' },
            { text: "prickly_pear_pad", image: 'textures/eternal/biome_craft/items/prickly_pear_pads' },
        ]
    }
];

const birchForestData = [
    {
        text: "birch_forest_blocks", image: 'textures/eternal/biome_craft/ui/category_blocks',
        subpages: [
            { text: "hollow_birch_log", image: 'textures/eternal/biome_craft/items/hollow_birch' },
            { text: "birch_leaves", image: 'textures/eternal/biome_craft/blocks/birch_leaves' },
            { text: "owl_nest", image: 'textures/eternal/biome_craft/blocks/owl_nest' },
            { text: "foxgloves", image: 'textures/eternal/biome_craft/items/foxglove' },
            { text: "wood_anemones", image: 'textures/eternal/biome_craft/items/tree_anemone' },
        ]
    },
    {
        text: "birch_forest_mobs", image: 'textures/eternal/biome_craft/ui/category_mobs',
        subpages: [
            { text: "owls", image: 'textures/eternal/biome_craft/ui/mobicon_owl' },
            { text: "bird", image: 'textures/eternal/biome_craft/ui/mobicon_bird_bluejay' },
            { text: "ram", image: 'textures/eternal/biome_craft/ui/mobicon_newsheep' },
        ]
    },
];

const oakForestData = [
    {
        text: "oak_forest_blocks", image: 'textures/eternal/biome_craft/ui/category_blocks',
        subpages: [
            { text: "apple_block", image: 'textures/eternal/biome_craft/items/apple_block' },
            { text: "oak_leaves", image: 'textures/eternal/biome_craft/blocks/orange_oak_leaves' },
            { text: "cloverfield", image: 'textures/eternal/biome_craft/items/clover' },
            { text: "cattail", image: 'textures/eternal/biome_craft/items/cattail' },
            { text: "duckweed", image: 'textures/eternal/biome_craft/blocks/duckweeds' },
            { text: "lily_pad", image: 'textures/eternal/biome_craft/items/lilypad' },
            { text: "bird_nest", image: 'textures/eternal/biome_craft/items/bird_nest' },
            { text: "squirrel_nest", image: 'textures/eternal/biome_craft/ui/nest' },
        ]
    },
    {
        text: "oak_forest_mobs", image: 'textures/eternal/biome_craft/ui/category_mobs',
        subpages: [
            { text: "squirrel", image: 'textures/eternal/biome_craft/ui/mobicon_red_squirrel' },
            { text: "duck", image: 'textures/eternal/biome_craft/ui/mobicon_mallardduck' },
            { text: "goose", image: 'textures/eternal/biome_craft/ui/mobicon_goose' },
            { text: "rooster", image: 'textures/eternal/biome_craft/ui/mobicon_copperrooster' },
            { text: "boar", image: 'textures/eternal/biome_craft/ui/mobicon_boar' },
        ]
    }
];

// Main guidebook data with all biomes
const homePageData = [
    { text: "how_to", image: 'textures/eternal/biome_craft/ui/howto', subpages: HowToData },
    { text: "veldtlands", image: 'textures/eternal/biome_craft/ui/biomeicon_veldtlands', subpages: veldtlandsData },
    { text: "tropical_rainforest", image: 'textures/eternal/biome_craft/ui/biomeicon_rainforest', subpages: tropicalRainforestData },
    { text: "redwood_forest", image: 'textures/eternal/biome_craft/ui/biomeicon_redwood', subpages: redwoodForestData },
    { text: "prairie", image: 'textures/eternal/biome_craft/ui/biomeicon_praire', subpages: prairieData },
    { text: "birch_forest", image: 'textures/eternal/biome_craft/ui/biomeicon_yellowbirch', subpages: birchForestData },
    { text: "oak_forest", image: 'textures/eternal/biome_craft/ui/biomeicon_seasonedoak', subpages: oakForestData },
    { text: "vote", image: 'textures/eternal/biome_craft/ui/vote' }
];
