import { world, Player } from "@minecraft/server";

import { multiButtonScriptDialogue } from "./MinecraftScriptDialogue";

//Script taken from Jigabov Guide Book Server UI implementation, adjusted to be run from scriptevent rather than item use. Naming convensions kept same.
const showDialogueOnItemUse =
  ({ EventTypeId, soundOnOpen, soundOnClose, title, content, exit }) =>
  async (event) => {
    if (event.id === EventTypeId) {
      const player = event.sourceEntity;
      if (player && player instanceof Player) {
        if (soundOnOpen) {
          player.playSound(soundOnOpen);
        }
        await multiButtonScriptDialogue(title).setBody(content).addButton("exit", exit).open({ player });
        if (soundOnClose) {
          player.playSound(soundOnClose);
        }
      } else {
      }
    }
  };

export default showDialogueOnItemUse;
