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


//initiate form
world.afterEvents.itemUse.subscribe(event => {
  if (event.itemStack.typeId === "redstone:guide_book") {
    const player = event.source
    //form code
    let form = new ActionFormData();
    form.title("The Explorer's Guide");
    form.body("A simple and quick guide to the mod's storylines! For full documentation, visit our wiki at: \n§lhttps://1d10t1c-stud10s.github.io/more-to-explore !");
    form.button("Rise of the Relicsmiths", "textures/items/relic")
    form.button("Piglin Gold", "textures/items/gold_ingot")
    form.button("Overseeing Tyrants", "textures/items/illager_axe")
    form.button("Deathly Debacle", "textures/items/rotten_flesh")
    form.button("The Great White Sky", "textures/items/sky_essence")
    form.button("To End it All", "textures/items/guide_book")

    //form button effects
    form.show(player).then(r => {
      if (r.canceled) return;

      let response = r.selection;
      switch (response) {
        case 0:
          player.sendMessage('§lPay a visit to a Tavern and buy "The Relic" book from the storyteller villager, it will tell you where to go next...');
          break;

        case 1:
          player.sendMessage('§lVisit the nether and locate an Elder Piglin, who will speak of the next step...')
          break;

        case 2:
          player.runCommandAsync('effect @s regeneration 3 1 true')
          player.runCommandAsync('damage @s 1')
          player.runCommandAsync('say @s The Illagers have been powerful for too long, locate the Plains Gatehouse, it is time we end this...')
          break;
        case 3:
          player.runCommandAsync('effect @s regeneration 2 1 true')
          player.runCommandAsync('damage @s 1')
          player.runCommandAsync('say @s Pay a visit to a Tavern and buy the "The 3 Undead Lords" book from the storyteller villager, it will tell you where to go next...')

        default:
      }
    }).catch(e => {
      console.error(e, e.stack);
    });
  };
});

