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:easy_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§dGravel Digger", "textures/blcoks/gravel");
    form.button("§l§dSimple Baking", "textures/items/bread");

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

      let response = r.selection;
      switch (response) {
        case 0:
          obtainquest("§l§dGravel Digger", "Gather 16 gravel! §lReward: Flint x4", 'minecraft:gravel', 16, 'minecraft:gravel', 4, player, true)
          break;

        case 1:
          obtainquest("§l§dSimple Baking", "Make 4 bread. §lReward: wheat x6", "minecraft:bread", 4, "minecraft:wheat", 6, player, true)
          break;

        case 2:

          break;

        case 3:

          break;

        case 4:

          break;

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