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

world.afterEvents.itemUse.subscribe(event => {
    const item = event.itemStack.typeId
    var player = event.source

    if (item === 'darkw_dotv:guidebook_vol1') {
        GuideBookMain(player)
    }
})

// Main Form
function GuideBookMain(player) {
    let GuideBook_MainForm = new ActionFormData()

    GuideBook_MainForm.title("Chronicle of The Void: Volume I")
    GuideBook_MainForm.body("Welcome to Disciples of The Void, Volume I!\n\nThis addon adds an array of powerful bosses to challenge your endgame equipment, along with giving you even MORE equipment in the process!\n\nBelow is a number of sections giving short prompts for each part of the pack. There isn't too much considering everything is already layed out pretty well.\n")
    GuideBook_MainForm.button("Crafting", "textures/items/darkw/dotv/ico_cra")
    GuideBook_MainForm.button("Equipment", "textures/items/darkw/dotv/ico_tmp")
    GuideBook_MainForm.button("Bosses", "textures/items/darkw/dotv/ico_bos")

    GuideBook_MainForm.show(player).then(r => {
        if (r.canceled) return

        switch (r.selection) {
            case 0:
                GuideBookPage1(player)
                break

            case 1:
                GuideBookPage2(player)
                break

            case 2:
                GuideBookPage3(player)
                break
        }
    })
}

// Page1
function GuideBookPage1(player) {
    let GuideBook_MainForm = new ActionFormData()

    GuideBook_MainForm.title("Page 1: Crafting")
    GuideBook_MainForm.body("§e§lCrafting:§r \nIn the crafting table, all recipes for boss summons are automatically unlocked (including this book).\n\n• This is so that you have a LOT to look forward to as you progress in the pack.\n\n• Each item requires this book in order to craft it, so make sure to stock up on knowledge!\n\n• Two more recipes are also there, but those are explained in the Equipment section of this book.\n")
    GuideBook_MainForm.button("Back", "textures/items/darkw/dotv/ico_gui")

    GuideBook_MainForm.show(player).then(r => {
        if (r.canceled) return
        if (r.selection === 0) GuideBookMain(player)
    })
}

function GuideBookPage2(player) {
    let GuideBook_MainForm = new ActionFormData()

    GuideBook_MainForm.title("Page 2: Equipment")
    GuideBook_MainForm.body("§e§lEquipment:§r\n• Five bosses drop their own weapon after defeating them, there are a total of six weapons to collect. One of them being more powerful than them all!\n\n§e§lAlatine Templates:§r\n• Alatar (The Wizard), has some weird looking minions that drop fragments for a smithing template that gives a sidegrade to Diamond Armor when combined with a netherite ingot. This is a good set of armor to take a lot of damage in and not sread your good armor!\n• This armor will give potion effects to users who wear the full set!\n\n§d§lThe Ultimate Weapon:§r\n• If you combine the swords from the main five bosses along with Alatine Templates, you can make the most powerful sword in the pack!")
    GuideBook_MainForm.button("Back", "textures/items/darkw/dotv/ico_gui")

    GuideBook_MainForm.show(player).then(r => {
        if (r.canceled) return
        if (r.selection === 0) GuideBookMain(player)
    })
}

function GuideBookPage3(player) {
    let GuideBook_MainForm = new ActionFormData()

    GuideBook_MainForm.title("Page 3: Bosses")
    GuideBook_MainForm.body("§e§lBosses:§r\nAt the time of writing this book there are five bosses in this pack, all bearing special abilities and weapons. \n\n• Netherite armor is STRONGLY recommended for each fight. \n\n• All bosses each drop their own weapon. They can be repaired with diamonds or combining multiple into one using the crafting grid unless said otherwise.\n\n• The Final Boss is available to fight at any time, but it is recommended that you fight everyone else first.")
    GuideBook_MainForm.button("Back", "textures/items/darkw/dotv/ico_gui")

    GuideBook_MainForm.show(player).then(r => {
        if (r.canceled) return
        if (r.selection === 0) GuideBookMain(player)
    })
}