import { world, system } from "@minecraft/server";
import { ActionFormData } from "@minecraft/server-ui";

world.afterEvents.itemUse.subscribe(event => {
	if (event.itemStack.typeId !== "mythicus_ws:waystone.guidebook.update") return;

	form_guidebook(event.source);
});

async function form_guidebook(player) {
	const form = new ActionFormData();
	form.title({ rawtext: [{ translate: "waystone.mythicus:ui.form.guidebook.update" }] });

	form.body({
		rawtext: [
			{ translate: "waystone.mythicus:ui.guidebook.update.1", "with": ["\n"] },
			{ "text": "\n\n" },
			{ translate: "waystone.mythicus:ui.guidebook.update.2", "with": ["\n"] },
			{ "text": "\n\n" },
			{ translate: "waystone.mythicus:ui.guidebook.update.3", "with": ["\n"] },
			{ "text": "\n\n" },
			{ translate: "waystone.mythicus:ui.guidebook.update.4", "with": ["\n"] },
			{ "text": "\n\n" },
			{ translate: "waystone.mythicus:ui.guidebook.update.5", "with": ["\n"] },
			{ "text": "\n\n" },
			{ translate: "waystone.mythicus:ui.guidebook.update.6", "with": ["\n"] },
			{ "text": "\n\n" },
			{ translate: "waystone.mythicus:ui.guidebook.update.7", "with": ["\n"] },
			{ "text": "\n\n" },
			{ translate: "waystone.mythicus:ui.guidebook.update.8", "with": ["\n"] },
			{ "text": "\n\n" },
			{ translate: "waystone.mythicus:ui.guidebook.update.9", "with": ["\n"] },
			{ "text": "\n\n" },
			{ translate: "waystone.mythicus:ui.guidebook.update.10", "with": ["\n"] },
			{ "text": "\n\n" },
			{ translate: "waystone.mythicus:ui.guidebook.update.11", "with": ["\n"] },
			{ "text": "\n\n" }
			
		]
	});

	form.button({ rawtext: [{ translate: "waystone.mythicus:ui.guidebook.update.continue" }] });

	player.playSound("item.book.page_turn", { volume: 1.0, pitch: 1.0 });
	form.show(player).then((response) => {
		player.playSound("item.book.page_turn", { volume: 1.0, pitch: 1.0 });
	});
}