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

world.afterEvents.itemUse.subscribe(event => {
  if (event.itemStack.typeId === "redstone:mage_quest") {
    const player = event.source
    //form code
    let form = new ActionFormData();
    form.title("§l§dMagic Quest Scroll");
    form.body("§dMagic Quests, §foften requiring you to complete simple tasks for fun magicks rewards.");
    form.button("§l§dMage I", "textures/items/spell_book");
    form.button("§l§dMage II", "textures/items/great_spell_book")
    form.button("§l§cPyromaniac", "textures/items/infernal_staff")

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

      let response = r.selection;
      switch (response) {
        case 0:
          obtainquest("§l§dMage I", "Get your hands on a spell book, ! §lReward: Book x8", 'redstone:spell_book', 1, 'minecraft:book', 8, player, true, true)
          break;

        case 1:
          obtainquest("§l§dMage II", "Gather 64 deepslate, venture into the deep! §lReward: Iron Ingot x16", "minecraft:cobbled_deepslate", 64, "minecraft:iron_ingot", 16, player, true, true)
          break;

        case 2:
          obtainquest("§l§cPyromaniac", "Craft an Infernal Staff, arson awaits you... §lReward: Fire Shield Book", "redstone:infernal_staff", 1, "redstone:fire_shield_book", 2, player, true, true)
          break;

        case 3:
          obtainquest("§l§dMiner IV", "Gather 48 diamonds, become a dwarvern miner! §lReward: Emerald Block x2", "minecraft:diamond", 16, "minecraft:emerald_block", 2, player, true, true)
          break;

        case 4:

          break;

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