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") return;

	form_guidebook(event.source);
});

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

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

	form.button({ rawtext: [{ translate: "waystone.mythicus:ui.guidebook.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 });
	});
}