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:storyline_quest") {
    const player = event.source
    //form code
    let form = new ActionFormData();
    form.title("§lStoryline Quest Scroll");
    form.body("§lStoryline Quests [WIP], §fthese quests are the main part of the questing system, §athis scroll is only to start storylines and finish storylines with rewards! §c§lNote that you may have to abort quest while completing some of these in order to attempt other side quests, you progress will be saved however.");
    form.button("§lRise of the Relicsmiths", "textures/items/relic");

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

      let response = r.selection;
      switch (response) {
        case 0:
          obtainquest("§lRise of the Relicsmiths", "Pay a visit to a tavern and buy the lost tale 'The Relic', it seems to be more than just a lost tale... §a§l[Check for completion only after obtaining the specified storyline item]", "redstone:relic_core", 1, "netherite_block", 2, player, false, false)
          break;

        case 1:

          break;

        case 2:

          break;
        case 3:


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

