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:mining_quest") {
    const player = event.source
    //form code
    let form = new ActionFormData();
    form.title("§l§aEasy Quest Scroll");
    form.body("§aEasy Quests, §foften requiring you to complete simple tasks for early game rewards.");
    form.button("§l§dMiner I", "textures/items/stone_pickaxe");
    form.button("§l§dMiner II", "textures/items/tin_pickaxe");
    form.button("§l§dMiner III", "textures/items/iron_pickaxe");
    form.button("§l§dMiner IV", "textures/items/steel_pickaxe");

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

      let response = r.selection;
      switch (response) {
        case 0:
          obtainquest("§l§dMiner I", "Gather 32 cobblestone, start your mining career! §lReward: Tin Ingot x8", "minecraft:cobblestone", 32, "redstone:tin_ingot", 8, player, true, true)
          break;

        case 1:
          obtainquest("§l§dMiner 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§dMiner III", "Gather 64 iron ingots, start the furnaces! §lReward: Tungsten x16", "minecraft:iron_ingot", 64, "redstone:tungsten", 16, 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:
          obtainquest("§l§dMiner V", "Gather 64 ancient debris, maybe don't sleep for a night? §lReward: Infernal Pickaxe", "minecraft:ancient_debris", 64, "redstone:infernal_pickaxe", 1, player, true, true)
          break;

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