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

//initiate form
world.afterEvents.itemUse.subscribe(event => {
  if (event.itemStack.typeId === "redstone:medium_quest") {
    const player = event.source
    //form code
    let form = new ActionFormData();
    form.title("§6Medium Quest Scroll");
    form.body("§6Medium Quests, §foften requiring you to kill things or obtain rare items, giving you mid-game items.");
    form.button("§l§cGunslinger", "textures/items/revolver")
    form.button("§l§gAhoi Matey!", "textures/items/cutlass")
    //form button effects
    form.show(player).then(r => {
      if (r.canceled) return;

      let response = r.selection;
      switch (response) {
        case 0:
          obtainquest("§l§cGunslinger", "Obtain a revolver, send your enemies... BULLET", "redstone:revolver", 1, "minecraft:arrow", 16, player, true, true)
          break;

        case 1:
          obtainquest("§l§gAhoi Matey", "Kill a Reaver illager, get a cutlass. §lReward: Gold Ingots x9", "redstone:cutlass", 1, "minecraft:gold_ingot", 9, player, true, true)
          break;
        case 2:


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

