import { world, system } from '@minecraft/server';
import { ActionFormData } from '@minecraft/server-ui';

const BookNext = {
    bee_book: "replaceitem entity @s slot.weapon.mainhand 0 ftb_bees:bee_book_0",
    bee_book_0: "replaceitem entity @s slot.weapon.mainhand 0 ftb_bees:bee_book_1",
    bee_book_1: "replaceitem entity @s slot.weapon.mainhand 0 ftb_bees:bee_book_2",
    bee_book_2: "replaceitem entity @s slot.weapon.mainhand 0 ftb_bees:bee_book_3",
    bee_book_3: "replaceitem entity @s slot.weapon.mainhand 0 ftb_bees:bee_book_4",
    bee_book_4: "replaceitem entity @s slot.weapon.mainhand 0 ftb_bees:bee_book_5",
    bee_book_5: "replaceitem entity @s slot.weapon.mainhand 0 ftb_bees:bee_book_6",
    bee_book_6: "replaceitem entity @s slot.weapon.mainhand 0 ftb_bees:bee_book_7",
    bee_book_7: "replaceitem entity @s slot.weapon.mainhand 0 ftb_bees:bee_book_8",
    bee_book_8: "replaceitem entity @s slot.weapon.mainhand 0 ftb_bees:bee_book_9",
    bee_book_9: "replaceitem entity @s slot.weapon.mainhand 0 ftb_bees:bee_book_10",
    bee_book_10: "replaceitem entity @s slot.weapon.mainhand 0 ftb_bees:bee_book_11",
    bee_book_11: "replaceitem entity @s slot.weapon.mainhand 0 ftb_bees:bee_book_12",
    bee_book_12: "replaceitem entity @s slot.weapon.mainhand 0 ftb_bees:bee_book_13",
    bee_book_13: "replaceitem entity @s slot.weapon.mainhand 0 ftb_bees:bee_book_14",
    bee_book_14: "replaceitem entity @s slot.weapon.mainhand 0 ftb_bees:bee_book_15",
    bee_book_15: "replaceitem entity @s slot.weapon.mainhand 0 ftb_bees:bee_book_16",
    bee_book_16: "replaceitem entity @s slot.weapon.mainhand 0 ftb_bees:bee_book",
};
const BookPrev = {
    bee_book_0: "replaceitem entity @s slot.weapon.mainhand 0 ftb_bees:bee_book",
    bee_book_1: "replaceitem entity @s slot.weapon.mainhand 0 ftb_bees:bee_book_0",
    bee_book_2: "replaceitem entity @s slot.weapon.mainhand 0 ftb_bees:bee_book_1",
    bee_book_3: "replaceitem entity @s slot.weapon.mainhand 0 ftb_bees:bee_book_2",
    bee_book_4: "replaceitem entity @s slot.weapon.mainhand 0 ftb_bees:bee_book_3",
    bee_book_5: "replaceitem entity @s slot.weapon.mainhand 0 ftb_bees:bee_book_4",
    bee_book_6: "replaceitem entity @s slot.weapon.mainhand 0 ftb_bees:bee_book_5",
    bee_book_7: "replaceitem entity @s slot.weapon.mainhand 0 ftb_bees:bee_book_6",
    bee_book_8: "replaceitem entity @s slot.weapon.mainhand 0 ftb_bees:bee_book_7",
    bee_book_9: "replaceitem entity @s slot.weapon.mainhand 0 ftb_bees:bee_book_8",
    bee_book_10: "replaceitem entity @s slot.weapon.mainhand 0 ftb_bees:bee_book_9",
    bee_book_11: "replaceitem entity @s slot.weapon.mainhand 0 ftb_bees:bee_book_10",
    bee_book_12: "replaceitem entity @s slot.weapon.mainhand 0 ftb_bees:bee_book_11",
    bee_book_13: "replaceitem entity @s slot.weapon.mainhand 0 ftb_bees:bee_book_12",
    bee_book_14: "replaceitem entity @s slot.weapon.mainhand 0 ftb_bees:bee_book_13",
    bee_book_15: "replaceitem entity @s slot.weapon.mainhand 0 ftb_bees:bee_book_14",
    bee_book_16: "replaceitem entity @s slot.weapon.mainhand 0 ftb_bees:bee_book_15",
};
world.beforeEvents.itemUse.subscribe((data) => {
    let player = data.source;
    const itemFullName = data.itemStack.typeId;
    const itemName = itemFullName.split(":")[1];
    if (BookNext[itemName] && player.isSneaking == false) {
        player.runCommandAsync("" + BookNext[itemName]);
        player.runCommandAsync("playsound item.book.page_turn @a ~~~");
    }
    if (BookPrev[itemName] && player.isSneaking == true) {
        player.runCommandAsync("" + BookPrev[itemName]);
        player.runCommandAsync("playsound item.book.page_turn @a ~~~");
    }
    if (data.itemStack.typeId == "ftb_bees:bee_book" && player.isSneaking == true) {
        system.run(() => bee_book_chapter(player));
    }
});
function bee_book_chapter(player) {
    const form = new ActionFormData()
        .title("Explore Buzzing About Bees!")
        .body("Choose a chapter to unlock the secrets of Feed the Bees.")
        .button("Changelogs", "textures/items/banner_pattern")
        .button("Introduction", "textures/ftb/bees/items/book")
        .button("Catching Bees", "textures/ftb/bees/items/jar_empty")
        .button("Breeding Bees", "textures/ui/health_boost_effect")
        .button("Harvesting Bees", "textures/items/brush")
        .button("Apiarist Table", "textures/ftb/bees/blocks/apiarists_bench_side")
        .button("Beeswax", "textures/ftb/bees/items/bees_wax")
        .button("Bee Storage", "textures/ftb/bees/items/bee_box/bee_box")
        .button("Crafting Bees", "textures/ftb/bees/blocks/apiarists_bench_top")
        .button("Beepedia", "textures/ftb/bees/items/beepedia")
        .button("Big Flowers", "textures/ftb/bees/items/flower_fertilizer")
        .button("Armour", "textures/ftb/bees/items/armour/bee_chestplate")
        .button("Decoritive Blocks", "textures/ftb/bees/blocks/honeycomb/honeycomb_brick")
        .button("Credits", "textures/items/book_writable")
        .button("Changelogs", "textures/items/banner_pattern")
        .button("§r§f§4Exit\n§7[ Click to Close ]", "textures/ui/redX1");
    form.show(player).then((r) => {
        if (r.selection == 0) {
            system.run(() => beepedia_changelog(player));
        }
        if (r.selection == 1) {
            player.runCommandAsync("replaceitem entity @s slot.weapon.mainhand 0 ftb_bees:bee_book_1");
        }
        if (r.selection == 2) {
            player.runCommandAsync("replaceitem entity @s slot.weapon.mainhand 0 ftb_bees:bee_book_2");
        }
        if (r.selection == 3) {
            player.runCommandAsync("replaceitem entity @s slot.weapon.mainhand 0 ftb_bees:bee_book_3");
        }
        if (r.selection == 4) {
            player.runCommandAsync("replaceitem entity @s slot.weapon.mainhand 0 ftb_bees:bee_book_5");
        }
        if (r.selection == 5) {
            player.runCommandAsync("replaceitem entity @s slot.weapon.mainhand 0 ftb_bees:bee_book_5");
        }
        if (r.selection == 6) {
            player.runCommandAsync("replaceitem entity @s slot.weapon.mainhand 0 ftb_bees:bee_book_6");
        }
        if (r.selection == 7) {
            player.runCommandAsync("replaceitem entity @s slot.weapon.mainhand 0 ftb_bees:bee_book_7");
        }
        if (r.selection == 8) {
            player.runCommandAsync("replaceitem entity @s slot.weapon.mainhand 0 ftb_bees:bee_book_8");
        }
        if (r.selection == 9) {
            player.runCommandAsync("replaceitem entity @s slot.weapon.mainhand 0 ftb_bees:bee_book_10");
        }
        if (r.selection == 10) {
            player.runCommandAsync("replaceitem entity @s slot.weapon.mainhand 0 ftb_bees:bee_book_11");
        }
        if (r.selection == 11) {
            player.runCommandAsync("replaceitem entity @s slot.weapon.mainhand 0 ftb_bees:bee_book_13");
        }
        if (r.selection == 12) {
            player.runCommandAsync("replaceitem entity @s slot.weapon.mainhand 0 ftb_bees:bee_book_15");
        }
        if (r.selection == 13) {
            player.runCommandAsync("replaceitem entity @s slot.weapon.mainhand 0 ftb_bees:bee_book_15");
        }
        if (r.selection == 14) {
            system.run(() => beepedia_changelog(player));
        }
    });
}
function beepedia_changelog(player) {
    const form = new ActionFormData()
        .title("Changelogs")
        .body("Choose a changelog below to learn more.")
        .button("Changelog v1.4.0(Latest)", "textures/items/banner_pattern")
        .button("Changelog v1.3.0", "textures/items/banner_pattern")
        .button("Changelog v1.2.0", "textures/items/banner_pattern")
        .button("Changelog v1.1.0", "textures/items/paper")
        .button("Changelog v1.0.2", "textures/items/paper")
        .button("Changelog v1.0.1", "textures/items/paper")
        .button("Changelog v1.0.0", "textures/items/banner_pattern")
        .button("§tBack\n§7[ Click to Return ]", "textures/ui/recap_glyph_color_2x");
    form.show(player).then((r) => {
        if (r.selection === 0) {
            system.run(() => beepedia_changelog_1_4_0(player));
        }
        if (r.selection === 1) {
            system.run(() => beepedia_changelog_1_3_0(player));
        }
        if (r.selection === 2) {
            system.run(() => beepedia_changelog_1_2_0(player));
        }
        if (r.selection === 3) {
            system.run(() => beepedia_changelog_1_1_0(player));
        }
        if (r.selection === 4) {
            system.run(() => beepedia_changelog_1_0_2(player));
        }
        if (r.selection === 5) {
            system.run(() => beepedia_changelog_1_0_1(player));
        }
        if (r.selection === 6) {
            system.run(() => beepedia_changelog_1_0_0(player));
        }
        if (r.selection === 7) {
            system.run(() => bee_book_chapter(player));
        }
    });
}
function beepedia_changelog_1_4_0(player) {
    const form = new ActionFormData()
        .title("Changelog v1.4.0")
        .body(`Feed the Bees§r §sv1.4.0 - 13/12/2024§r\n\n§uFeatures§r\n\n- Introduced the Pale Oak Bee Box.\n- Added the Pale Oak Bee and the Resin Bee.\n- Implemented Raw Diamond and Raw Emerald as both items and blocks.\n\n§uChanges§r\n\n- Iron, gold, copper, diamond, and emerald honeycombs now refine into raw ore instead of ingots.\n\n§tBug Fixes§r\n\n- Resolved various issues related to bee boxes.`)
        .button("§tBack\n§7[ Click to Return ]", "textures/ui/recap_glyph_color_2x");
    form.show(player).then((r) => {
        if (r.selection === 0) {
            system.run(() => beepedia_changelog(player));
        }
    });
}
function beepedia_changelog_1_3_0(player) {
    const form = new ActionFormData()
        .title("Changelog v1.3.0")
        .body(`Feed the Bees§r §sv1.3.0 - 12/09/2024§r\n\n§tBug Fixes§r\n\n- Oak bee boxes are once again placeable.\n- Inconsistent text in books has been corrected.\n- Bee boxes no longer duplicate in water.\n- The Glass Bee is now fully dyable.\n- Red netherbrick bee now works in the Bee Box.\n\n§uChanges§r\n\n- Bee spawning and despawning have been rebalanced (skeleton bees are now much rarer).`)
        .button("§tBack\n§7[ Click to Return ]", "textures/ui/recap_glyph_color_2x");
    form.show(player).then((r) => {
        if (r.selection === 0) {
            system.run(() => beepedia_changelog(player));
        }
    });
}
function beepedia_changelog_1_2_0(player) {
    const form = new ActionFormData()
        .title("Changelog v1.2.0")
        .body(`§pFeed the Bees§r §sv1.2.0 - 02/09/2024§r\n\n§tBug Fixes§r\n\n- Dark Oak and Spruce Bees can now be placed in jars.\n- Bee Boxes no longer accept any items as input.\n- Blackstone Bees can be removed from Bee Boxes without issues.\n- Bee Boxes no longer move when saving and quitting the game.\n- Bee Boxes can now be placed on Sea Lanterns.\n\n§uChanges§r\n\n- The spawn rate of bees has been decreased.\n- The drop rates from Bee Boxes have been reduced.\n- More information has been added to the main Bee Book.`)
        .button("§tBack\n§7[ Click to Return ]", "textures/ui/recap_glyph_color_2x");
    form.show(player).then((r) => {
        if (r.selection === 0) {
            system.run(() => beepedia_changelog(player));
        }
    });
}
function beepedia_changelog_1_1_0(player) {
    const form = new ActionFormData()
        .title("Changelog v1.1.0")
        .body(`§pFeed the Bees§r §sv1.1.0 - 15/08/2024§r\n\n§tBug Fixes§r\n\n- Fixed Empty Jar recipe.\n\n- Fixed Flower Fertilizer recipe.`)
        .button("§tBack\n§7[ Click to Return ]", "textures/ui/recap_glyph_color_2x");
    form.show(player).then((r) => {
        if (r.selection === 0) {
            system.run(() => beepedia_changelog(player));
        }
    });
}
function beepedia_changelog_1_0_2(player) {
    const form = new ActionFormData()
        .title("Changelog v1.0.1")
        .body(`§pFeed the Bees§r §sv1.0.2 - 09/08/2024§r\n\n§tBug Fixes§r\n\n- Addressed issues in multiple recipes.\n\n- Corrected block and item names for consistency.\n\n- Fixed a grammatical error in the in-game book.`)
        .button("§tBack\n§7[ Click to Return ]", "textures/ui/recap_glyph_color_2x");
    form.show(player).then((r) => {
        if (r.selection === 0) {
            system.run(() => beepedia_changelog(player));
        }
    });
}
function beepedia_changelog_1_0_1(player) {
    const form = new ActionFormData()
        .title("Changelog v1.0.1")
        .body(`§pFeed the Bees§r §sv1.0.1 - 06/08/2024§r\n\n§qFeatures§r\n\n- Vanilla bees can now be collected in Empty Jars.\n\n- Added recipes for crafting the in-game books.\n\n§tBug Fixes§r\n\n- Corrected the in-game book to accurately reference jars instead of bottles.\n\n- Resolved the issue where the Copper Bee texture was not displaying correctly.\n\n- Fixed various loot table inconsistencies.\n\n- Addressed problems with chapter selection.\n\n§uImprovements§r\n\n- Implemented a "Changelogs" button at the top and bottom of the chapter select screen for easy access to update information.\n\n- Enhanced the user interface by adding icons to the "Exit" and "Back" buttons for better clarity.`)
        .button("§tBack\n§7[ Click to Return ]", "textures/ui/recap_glyph_color_2x");
    form.show(player).then((r) => {
        if (r.selection === 0) {
            system.run(() => beepedia_changelog(player));
        }
    });
}
function beepedia_changelog_1_0_0(player) {
    const form = new ActionFormData()
        .title("Changelog v1.0.0")
        .body("§pFeed the Bees§r §sv1.0.0 - 25/07/2024§r\n\n- Initial Submission.")
        .button("§tBack\n§7[ Click to Return ]", "textures/ui/recap_glyph_color_2x");
    form.show(player).then((r) => {
        if (r.selection === 0) {
            system.run(() => beepedia_changelog(player));
        }
    });
}
