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:deathlydebacle_book") {
    const player = event.source
    //form code
    let form = new ActionFormData();
    form.title("§lThe 3 Undead Lords");
    form.body("The three dark Undead Lords, Rot, Reanimator and the Frostbitten need to be slain, before we all get consumed by the undead... Some say they reside in the Deserts, Ice Plains and the Nether itself...");
    form.button("§l§cClose Book");

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

      let response = r.selection;
      switch (response) {
        case 0:
          player.sendMessage('§lyou closed the book');
          break;

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

