import { system, Player } from "@minecraft/server";
import { ActionFormData, MessageFormResponse, MessageFormData } from "@minecraft/server-ui";

// OPEN UI
system.afterEvents.scriptEventReceive.subscribe(({id, sourceEntity}) => {
	if (sourceEntity === undefined || sourceEntity?.typeId !== "minecraft:player") return;
	if (id === "oct_plev:main_ui") main_ui(sourceEntity);
})

// UI
function main_ui(player) {
	let main_ui = new ActionFormData()

	.title("Evolve") // name of the ui
	.body(" \n\n\n")
	.button("Claim Rewards")
	.button("Open Skill Tree")

	main_ui.show(player).then((r) => {
		if (r.selection !== undefined) {
			switch (r.selection) {
				case 0:
					player.runCommand("/function oct/plev/experience/get_rewards"); // CLAIM REWARDS
					break;
				case 1:
					player.runCommand("/scriptevent oct_plev:skill_tree"); // OPEN SKILL TREE
					break;
				default:
					break;
			}
		}
	});
}