import * as mc from "@minecraft/server";
import * as ui from "@minecraft/server-ui";

const VERSION = "1.0.0";
const SOUND_TURN_PAGE = "item.book.page_turn";
const SOUND_OPTIONS = { pitch: 1.0, volume: 5.0, };

export const MENUS = [
	//MAIN MENU
    {
        menuID: "sgs_farm:main",
        title: "Main Menu",
        body: "Welcome to §aHarvestcraft§r!\n\nThis Add-On expands §nFarming§r, §nCooking§r\n& §nDecorations§r with various additions.\n\nRead the §aBasics§r section to begin.",
        buttons: [
            {
                title: "Basics",
                icon:  "textures/sgs/farm/items/icons/icon_basics",
                connectID: "sgs_farm:tutorial"
            },
            {
                title: "Chapters",
                icon:  "textures/sgs/farm/items/icons/icon_chapters",
                connectID: "sgs_farm:modules"
            },
            {
                title: "About",
                icon:  "textures/sgs/farm/items/icons/icon_about",
                connectID: "sgs_farm:about"
            }
        ],
        type: "form",
        openOnBlock: ""
    },
	
	//TUTORIAL MENU - THE BASICS
	
    {
        menuID: "sgs_farm:tutorial",
        title: "The Basics",
        body: "Read this section first to know how to get started on §afarming§r and §ncrafting§r.\n\n",
        buttons: [
			{
                title: "Blueprints",
                icon:  "textures/sgs/farm/items/tools/item_blueprint",
                connectID: "sgs_farm:blueprint"
            },
			{
                title: "Workstations",
                icon:  "textures/sgs/farm/items/icons/icon_workbench",
                connectID: "sgs_farm:workbench"
            },
            {
                title: "Wild Seeds",
                icon:  "textures/sgs/farm/items/misc/item_wild_seed",
                connectID: "sgs_farm:wild_seeds"
            },

			{
                title: "Return",
                icon:  "textures/sgs/farm/items/icons/icon_return",
                connectID: "sgs_farm:main"
            }
        ],
        type: "form",
        openOnBlock: ""
    },
	{
        menuID: "sgs_farm:blueprint",
        title: "Blueprints",
        body: "To craft §aHarvestCraft§r items, you first need some §nBlueprints§r\n\nIt only requires this Guidebook and some paper to craft. Check for it in the §ncrafting menu§r.\n\nTo use the §aBlueprints§r, you also need a §nWorkbench§r, which likewise requires this Guidebook and some wood.\n\nNow, as a §afinal step§r to get started, you need to place the §nBlueprints§r on top of the §nWorkbench§r, combining them into a §nBlueprint Workstation§r\n\nFrom this, you can craft most §aHarvestcraft§r items.",
        buttons: [
            { 
                title: "Return",
                icon:  "textures/sgs/farm/items/icons/icon_return",
                connectID: "sgs_farm:tutorial"
            }
        ],
        type: "form",
        openOnBlock: ""
    },
	{
        menuID: "sgs_farm:workbench",
        title: "Workstations",
        body: "Most crafting in §aHarvestCraft§r is done with §n2-Part Workstations§r, made from a §nbase§r and an §nimplement§r on top.\n\nThe §aBlueprint Workstation§r is an example of this, but the Workbench has more implements as well.\n\n§aWorkbench Implements:§r\n- Blueprints\n- Handsaw\n- Paint Station\n\n§aStove Implements:§r\n- Stove Oven\n- Stove Pot\n- Stove Pan\n\n§aPrep Table:§r\n- Chopping Board\n\nThere are also special §aWorkstations§r like the §nKiln§r or §nMillstone§r which follow different rules explained in their specific sections.",
        buttons: [
            { 
                title: "Return",
                icon:  "textures/sgs/farm/items/icons/icon_return",
                connectID: "sgs_farm:tutorial"
            }
        ],
        type: "form",
        openOnBlock: ""
    },
	{
        menuID: "sgs_farm:wild_seeds",
        title: "Wild Seeds",
        body: "To start farming §aHarvestcraft§r crops, you first need to collect some §nWild Seeds§r, which have a chance to drop when breaking §ngrass§r, §ntall grass§r or §nfern§r.\n\nThe §aWild Seeds§r can then be processed into all kinds of seeds with a §nSeed Processor§r, which you will need to craft with a §nworkbench§r.",
        buttons: [
            {
                title: "Return",
                icon:  "textures/sgs/farm/items/icons/icon_return",
                connectID: "sgs_farm:tutorial"
            }
        ],
        type: "form",
        openOnBlock: ""
    },
	
	// MODULE MENUS - MAIN
	
	{
        menuID: "sgs_farm:modules",
        title: "Chapters",
        body: "Choose §aHarvestcraft Chapter§r:",
        buttons: [
            {
                title: "Farming",
                icon:  "textures/sgs/farm/items/item_turnip",
                connectID: "sgs_farm:farming"
            },
			{
                title: "Cooking",
                icon:  "textures/sgs/farm/items/food/item_roast_dinner_chicken",
                connectID: "sgs_farm:cooking"
            },
			{
                title: "Crafting",
                icon:  "textures/sgs/farm/items/icons/icon_crafting",
                connectID: "sgs_farm:crafting"
            },
			{
                title: "Machines",
                icon:  "textures/sgs/farm/items/entities/item_cart_cargo_oak",
                connectID: "sgs_farm:machines"
            },
			{
                title: "More",
                icon:  "textures/sgs/farm/items/icons/icon_more",
                connectID: "sgs_farm:more"
            },
			{
                title: "Return",
                icon:  "textures/sgs/farm/items/icons/icon_return",
                connectID: "sgs_farm:main"
            },
        ],
        type: "form",
        openOnBlock: ""
    },
	
	//MODULE MENUS - FARMING
	
	{
        menuID: "sgs_farm:farming",
        title: "Farming",
        body: "Learn how to §nacquire§r, §nplant§r & §nharvest§r §acrops§r & §afruit trees§r.",
        buttons: [
            {
                title: "Seeds",
                icon:  "textures/sgs/farm/items/seed_turnip",
                connectID: "sgs_farm:seeds"
            },
			{
                title: "Frames",
                icon:  "textures/sgs/farm/items/icons/icon_a_frame",
                connectID: "sgs_farm:frames"
            },
			{
                title: "Watering",
                icon:  "textures/sgs/farm/items/icons/icon_watering_can",
                connectID: "sgs_farm:watering"
            },
			{
                title: "Harvesting",
                icon:  "textures/sgs/farm/items/tools/item_sickle_iron",
                connectID: "sgs_farm:harvesting"
            },
			{
                title: "Fruit Trees",
                icon:  "textures/sgs/farm/items/sapling_fruit_cherry",
                connectID: "sgs_farm:fruit_trees"
            },
			{
                title: "Return",
                icon:  "textures/sgs/farm/items/icons/icon_return",
                connectID: "sgs_farm:modules"
            }
        ],
        type: "form",
        openOnBlock: ""
    },
	{
        menuID: "sgs_farm:seeds",
        title: "Seeds",
        body: "There are 4 ways to acquire §aHarvestCraft Seeds§r.\n\n§aWild Seeds:§r\nCollect §nWild Seeds§r from breaking grass and put them through a §nSeed Processor§r to get a random seed.\n\n§aSeed Recycler:§r\nIf you have 4 of any seed that you don't want, you can put them in the §nSeed Recycler§r to turn them into a new random seed.\n\n§aFrom Crops:§r\nYou can craft any crop into 4 of its corresponding seed by placing it in your §ncrafting grid§r.\n\n§aHarvest Trader:§r\nA wandering §nHarvest Trader§r may show up to trade seeds with you.",
        buttons: [
            {
                title: "Return",
                icon:  "textures/sgs/farm/items/icons/icon_return",
                connectID: "sgs_farm:farming"
            }
        ],
        type: "form",
        openOnBlock: ""
    },
	{
        menuID: "sgs_farm:frames",
        title: "Frames",
		body: "§aSeeds§r will display what they need to be planted on. Regular §nFarmland§r or one of §n3 Frames§r.\n\n§aFarmland:§r\nThese seeds can be placed onto regular Farmland or into §nPlanters§r.\n\n§aFrames:§r\nSome seeds must be placed onto either an §nA-Frame§r, a §nP-Frame§r or a §nVine-Frame§r which also need to be placed onto §nFarmland§r first.\n\nThe §aFrames§r can be crafted with a §nBlueprint Workstation§r\n\n§aVine-Frame:§r\nVine-Frames are also special in that they can be §nstacked§r up to §n5 blocks§r high like §nScaffolding§r. Their crops are planted onto the lowest §nVine-Frame§r and will grow higher over time.",
        buttons: [
            {
                title: "Return",
                icon:  "textures/sgs/farm/items/icons/icon_return",
                connectID: "sgs_farm:farming"
            }
        ],
        type: "form",
        openOnBlock: ""
    },
	{
        menuID: "sgs_farm:watering",
        title: "Watering",
		body: "A §aWatering Can§r is a good alternative to keep your §nFarmland§r wet.\n\nUse it on §aFarmland§r to water a §n3x3 area§r around its center.\n\n§aFarmland§r watered in this way will stay §nirrigated§r for a long time and has a chance to §nboost§r crop growth.",
        buttons: [
            {
                title: "Return",
                icon:  "textures/sgs/farm/items/icons/icon_return",
                connectID: "sgs_farm:farming"
            }
        ],
        type: "form",
        openOnBlock: ""
    },
	{
        menuID: "sgs_farm:harvesting",
        title: "Harvesting",
        body: "§aHarvestCraft§r crops can be harvested with a special item, the §nSickle§r.\n\nSimply §ainteract§r with a fully grown crop with a §nSickle§r to harvest the crop.\n\nThis method keeps the §aplant§r remaining in the ground so that it can immediately start growing a new crop, without needing to plant a new seed.",
        buttons: [
            {
                title: "Return",
                icon:  "textures/sgs/farm/items/icons/icon_return",
                connectID: "sgs_farm:farming"
            }
        ],
        type: "form",
        openOnBlock: ""
    },
	{
        menuID: "sgs_farm:fruit_trees",
        title: "Fruit Trees",
        body: "You may also get §aFruit Tree Saplings§r as seeds. These need to placed like regular saplings and will then grow into §nFruit Trees§r.\n\n§aFruit Trees§r will periodically grow fruit directly underneath their leaves.\n\nThese can be §aharvested§r by simply breaking them.\n\nYou can also §abreak & replace§r the fruit tree's leaves. Howevery hand-placed leaves will no longer grow blossoms or fruit on their own, only with §nbone meal§r.",
        buttons: [
            {
                title: "Return",
                icon:  "textures/sgs/farm/items/icons/icon_return",
                connectID: "sgs_farm:farming"
            }
        ],
        type: "form",
        openOnBlock: ""
    },
	
	//MODULE MENUS - COOKING
	
	{
        menuID: "sgs_farm:cooking",
        title: "Cooking",
        body: "Learn how to cook your §acrops§r into delicious §ameals§r.",
        buttons: [
            {
                title: "Stove",
                icon:  "textures/sgs/farm/items/icons/icon_stove",
                connectID: "sgs_farm:stove"
            },
			{
                title: "Prep Table",
                icon:  "textures/sgs/farm/items/icons/icon_prep_table",
                connectID: "sgs_farm:prep_table"
            },
			{
                title: "Millstone",
                icon:  "textures/sgs/farm/items/icons/icon_millstone",
                connectID: "sgs_farm:millstone"
            },
			{
                title: "Return",
                icon:  "textures/sgs/farm/items/icons/icon_return",
                connectID: "sgs_farm:modules"
            }
        ],
        type: "form",
        openOnBlock: ""
    },
	{
        menuID: "sgs_farm:stove",
        title: "Stove",
        body: "You'll need a §aStove§r for most meals. Like the §nWorkbench§r, it is a base that needs implements placed on top of it.\n\nEach §aimplement§r that fits on top is a different §nkitchen utensil§r, used to prepare different kinds of meals.\n\nSome recipes require a §nPlate§r or §nCeramic Dish§r which you can craft in a §aKiln§r.\n\n§aWorks with:\n§r- Stove Pot\n- Stove Pan\n- Stove Oven",
        buttons: [
            {
                title: "Return",
                icon:  "textures/sgs/farm/items/icons/icon_return",
                connectID: "sgs_farm:cooking"
            }
        ],
        type: "form",
        openOnBlock: ""
    },
	{
        menuID: "sgs_farm:prep_table",
        title: "Prep Table",
        body: "The §aPrep Table§r is a base for more basic recipes, basically whenever something needs §nchopping§r.\n\nIt only has one implement,\nthe §aChopping Board§r.",
        buttons: [
            {
                title: "Return",
                icon:  "textures/sgs/farm/items/icons/icon_return",
                connectID: "sgs_farm:cooking"
            }
        ],
        type: "form",
        openOnBlock: ""
    },
	{
        menuID: "sgs_farm:millstone",
        title: "Millstone",
        body: "The §aMillstone§r is much more basic than the other stations.\n\nIt doesn't need an §nimplement§r and is mostly used to grind §ngrains§r into §nflour§r.\n\nCheck out the different §aWorkstations§r in §nSurvival Mode§r to see all the available recipes.",
        buttons: [
            {
                title: "Return",
                icon:  "textures/sgs/farm/items/icons/icon_return",
                connectID: "sgs_farm:cooking"
            }
        ],
        type: "form",
        openOnBlock: ""
    },
	
	// MODULE MENUS - CRAFTING
	
	{
        menuID: "sgs_farm:crafting",
        title: "Crafting",
        body: "Learn how to make §adecorative blocks§r.",
        buttons: [
            {
                title: "Decorations",
                icon:  "textures/sgs/farm/items/icons/item_saw_hand",
                connectID: "sgs_farm:decorations"
            },
			{
                title: "Woodpainting",
                icon:  "textures/sgs/farm/items/icons/icon_wood_painting",
                connectID: "sgs_farm:woodpainting"
            },
			{
                title: "Pots & Planters",
                icon:  "textures/sgs/farm/items/icons/icon_pots",
                connectID: "sgs_farm:pots"
            },
			{
                title: "Kiln",
                icon:  "textures/sgs/farm/items/food/item_plate",
                connectID: "sgs_farm:kiln"
            },
			{
                title: "Juice & Jam",
                icon:  "textures/sgs/farm/items/food/item_juice_apple",
               connectID: "sgs_farm:juice"
          },
			{
                title: "Return",
                icon:  "textures/sgs/farm/items/icons/icon_return",
                connectID: "sgs_farm:modules"
            }
        ],
        type: "form",
        openOnBlock: ""
    },
	{
        menuID: "sgs_farm:decorations",
        title: "Decorations",
        body: "To craft various §awoodworks§r that fit into your farmstead, you need to place a §nHandsaw§r on top of a §nWorkbench§r.\n\nFrom here you can craft many different §nFences§r, §nGates§r, §nWindows§r,\nand §nKegs§r.\n\nWorks with any type of §awooden planks§r.",
        buttons: [
            {
                title: "Return",
                icon:  "textures/sgs/farm/items/icons/icon_return",
                connectID: "sgs_farm:crafting"
            }
        ],
        type: "form",
        openOnBlock: ""
    },
	{
        menuID: "sgs_farm:woodpainting",
        title: "Woodpainting",
        body: "You can also §apaint§r §nwooden planks§r in any of the 16 available §ndye colors§r.\n\nTo do so, you need a §aWorkbench§r with a §nPainting Kit§r topping.\n\nThere are also §a2 new dyes§r that can be crafted and applied to §nwooden planks§r,\n§2Dark Green§r & §4Dark Red§r.",
        buttons: [
            {
                title: "Return",
                icon:  "textures/sgs/farm/items/icons/icon_return",
                connectID: "sgs_farm:crafting"
            }
        ],
        type: "form",
        openOnBlock: ""
    },
	{
        menuID: "sgs_farm:kiln",
        title: "Kiln",
        body: "§aKilns§r are a special multiblock §nWorkstation§r.\n\nTo build one, place 8 §nKiln Brick Blocks§r, crafted at a §nBlueprint Workstation§r in a 2x2x2 cube arrangement.\n\nOnce the blocks transform to form a kiln, it is properly built.\n\n§aKiln Recipes:§r\n- Jars\n- Bottles\n- Plate\n- Ceramic Dish\n- Rubber\n- Kiln-Fired Stones.",
        buttons: [
            {
                title: "Return",
                icon:  "textures/sgs/farm/items/icons/icon_return",
                connectID: "sgs_farm:crafting"
            }
        ],
        type: "form",
        openOnBlock: ""
    },
	{
        menuID: "sgs_farm:pots",
        title: "Pots & Planters",
        body: "If you want to have your §aplants§r inside, you can craft §nPots & Planters§r.\n\n§aHerb Pots:§r\nA simple §npot§r that you can place any herb into.\n\nAccepts: §nThyme§r, §nRosemary§r, §nLavender§r, §nBasil§r, §nMint§r and §nCilantro§r\n\nYou can place up to §n4 pots§r into one block space. Harvest your §nherbs§r with a Sickle to leave the pots intact.\n\n§aPlanters:§r\nA §nPlanter§r for crops that can be placed anywhere.\n\nThey §aWater§r crops §nautomatically§r and connect to each other.",
        buttons: [
            {
                title: "Return",
                icon:  "textures/sgs/farm/items/icons/icon_return",
                connectID: "sgs_farm:crafting"
            }
        ],
        type: "form",
        openOnBlock: ""
    },
	{
        menuID: "sgs_farm:juice",
        title: "Juice & Jam",
        body: "The §aFruit Press§r is a special multiblock §nWorkstation§r.\n\nTo build it, place §n8 Fruit Press§r blocks, crafted at a §nBlueprint Workstation§r in a 2x2x2 cube arrangement.\n\nOnce the blocks transform to form a large vat, it is properly built.\n\nUse it with Bottles or Jars & fruit to craft §nJuice & Jam§r\n\nYou can §adisplay§r your Jars & Bottles in §nBottle Racks§r & §nJar Shelves§r respectively, which hold up to 4 each.",
        buttons: [
            {
                title: "Return",
                icon:  "textures/sgs/farm/items/icons/icon_return",
                connectID: "sgs_farm:crafting"
            }
        ],
        type: "form",
        openOnBlock: ""
    },
	
	// MODULE MENUS - MACHINES
	
	{
        menuID: "sgs_farm:machines",
        title: "Machines",
        body: "Learn about useful §amachines§r for farming.",
        buttons: [
            {
                title: "Shire Horse",
                icon:  "textures/sgs/farm/items/icons/icon_shirehorse",
                connectID: "sgs_farm:shire_horse"
            },
			{
                title: "Tractors",
                icon:  "textures/sgs/farm/items/entities/item_tractor",
                connectID: "sgs_farm:tractors"
            },
			{
                title: "Carts",
                icon:  "textures/sgs/farm/items/entities/item_cart_harvest",
                connectID: "sgs_farm:carts"
            },

			{
                title: "Sprinklers",
                icon:  "textures/sgs/farm/items/icons/icon_sprinklers",
                connectID: "sgs_farm:sprinklers"
            },
			{
                title: "Return",
                icon:  "textures/sgs/farm/items/icons/icon_return",
                connectID: "sgs_farm:modules"
            }
        ],
        type: "form",
        openOnBlock: ""
    },
	{
        menuID: "sgs_farm:shire_horse",
        title: "Shire Horse",
//        body: "§aShire Horses§r spawn in the world just like regular horses.\n\nThey can be tamed and saddled, but they can also be given a §aharness§r that allows them to pull §nmachine carts§r.\n\nTo attach a §aharnessed Shire Horse§r to a nearby §ncart§r, simply use a §nwrench§r on the §ncart§r.\n\nIf the cart is close enough, it will attach and you can ride your §nShire Horse§r to pull it.\n\nTo §adisconnect§r it again, simply use the §nwrench§r on the §ncart§r again.",
          body: "§aShire Horses§r spawn in §nPlains§r and §nSavannas§r. They can be tamed just like regular horses.\n\nThey can also be given a §aharness§r that allows them to pull §nmachine carts§r. Though once put on, you can't remove the §nharness§r from a §nShire Horse§r\n\nTo attach a §acart§r to a §nharnessed Shire Horse§r, simply put it into the horse's §nsaddle slot§r.\n\nShire Horses can be ridden, §njump§r or be §nleashed§r like regular horses.",
        buttons: [
            {
                title: "Return",
                icon:  "textures/sgs/farm/items/icons/icon_return",
                connectID: "sgs_farm:machines"
            }
        ],
        type: "form",
        openOnBlock: ""
    },
	{
        menuID: "sgs_farm:carts",
        title: "Machine Carts",
        body: "There are 4 different §amachine carts§r, a §nPlough§r, a §nPlanter§r and a §nHarvester§r.\n\n§aPlough:§r\nPull & hold jump over §ndirt§r to turn it into §nfarmland§r.\n\n§aPlanter:§r\nWith any §nHarvestCraft seends§r in the §NShire Horse's§r or §nTractor's§r inventory, pull & hold jump over §nfarmland§r to plant the seeds from the inventory.\n\n§aHarvester:§r\nPull over §nfully grown crops§r & hold jump to §nharvest§r them and put them into the §nShire Horse's§r or §nTractor's§r inventory.\n\n§aCargo:§r\nOnly works on §nShire Horse§r. Adds a decorative cargo cart.",
        buttons: [
            {
                title: "Return",
                icon:  "textures/sgs/farm/items/icons/icon_return",
                connectID: "sgs_farm:machines"
            }
        ],
        type: "form",
        openOnBlock: ""
    },
	{
        menuID: "sgs_farm:tractors",
        title: "Tractors",
//        body: "To attach a §aTractor§r to a nearby §ncart§r, simply use a §nwrench§r on the §ncart§r.\n\nIf the cart is close enough, it will attach and you can ride your\n§nTractor§r to pull it.\n\nTo §adisconnect§r it again, simply use the §nwrench§r on the §ncart§r again.",
          body: "§aTractors§r are machines that can pull carts to §nplough§r, §nsow§r, and §nharvest§r your fields with different machine attachments.\n\n§nTo attach a §aTractor§r to a §ncart§r, simply put it into the tractor's §nsaddle slot§r",
        buttons: [
            {
                title: "Return",
                icon:  "textures/sgs/farm/items/icons/icon_return",
                connectID: "sgs_farm:machines"
            }
        ],
        type: "form",
        openOnBlock: ""
    },
	{
        menuID: "sgs_farm:sprinklers",
        title: "Sprinklers",
        body: "A §aSprinkler§r will keep §nfarmland§r in a 13x13x3 area around its center §nwet§r if its connected to a §nWater Pump§r.\n\nA §aWater Pump§r must be placed directly over water and be connected to a §nSprinkler§r with §nGround Pipes§r to keep them up with water. Only a single §nWater Pump§r is needed for many §nSprinklers§r but they need to be connected to the §nWater Pump§r across §n15 Ground Pipes§r or less, otherwise they won't get enough water.\n\nPumps and Pipes will have a §nblue§r indicator whent they're properly connected to water.\n\n§ainteract§r with a §nSprinkler§r to see which blocks it waters.",
        buttons: [
            {
                title: "Return",
                icon:  "textures/sgs/farm/items/icons/icon_return",
                connectID: "sgs_farm:machines"
            }
        ],
        type: "form",
        openOnBlock: ""
    },
	
	// MODULE MENUS - MORE
	
	{
        menuID: "sgs_farm:more",
        title: "More",
        body: "Learn about §aTrade§r & §aFlowers§r.",
        buttons: [
            {
                title: "Harvest Trader",
                icon:  "textures/sgs/farm/items/icons/icon_trader",
                connectID: "sgs_farm:harvest_trader"
            },
			{
                title: "Meadow Flowers",
                icon:  "textures/sgs/farm/items/flowers/item_flower_meadow_poppy",
                connectID: "sgs_farm:meadow"
            },
            {
                title: "Ivy",
                icon:  "textures/sgs/farm/items/flowers/item_flower_bush_ivy",
                connectID: "sgs_farm:ivy"
            },
			{
                title: "Return",
                icon:  "textures/sgs/farm/items/icons/icon_return",
                connectID: "sgs_farm:modules"
            }
        ],
        type: "form",
        openOnBlock: ""
    },
	{
        menuID: "sgs_farm:harvest_trader",
        title: "Harvest Trader",
        body: "a wandering §aHarvest Trader§r may sometimes show up in your World.\n\nThey will buy your §ncrops§r and §nmeals§r and sell some §nrare seeds§r in return.",
        buttons: [
            {
                title: "Return",
                icon:  "textures/sgs/farm/items/icons/icon_return",
                connectID: "sgs_farm:more"
            }
        ],
        type: "form",
        openOnBlock: ""
    },
	{
        menuID: "sgs_farm:meadow",
        title: "Meadow Flowers",
        body: "The §aHarvest Trader§r may also sell you some §nFlower Fertilizer§r.\n\nThis special fertilizer, when activated on §agrass§r, will let §nMeadow Flowers§r grow and turn some of the grass into §nMeadow Grass§r.\n\nUse it to set up your own, special §nFlower Garden§r.",
        buttons: [
            {
                title: "Return",
                icon:  "textures/sgs/farm/items/icons/icon_return",
                connectID: "sgs_farm:more"
            }
        ],
        type: "form",
        openOnBlock: ""
    },
    {
        menuID: "sgs_farm:ivy",
        title: "Ivy",
        body: "With §aVine§r and some §nBone Meal§r, you can craft §nIvy at a §nBlueprint Workstation§r.\n\n§aIvy§r is a decorative plant that can attach to any block.\n\nYou can also make §aHanging Ivy§r by crafting it together with a §nHerb Pot§r.",
        buttons: [
            {
                title: "Return",
                icon:  "textures/sgs/farm/items/icons/icon_return",
                connectID: "sgs_farm:more"
            }
        ],
        type: "form",
        openOnBlock: ""
    },
	
	//ABOUT MENU
	
    {
        menuID: "sgs_farm:about",
        title: "About the Add-On",
        body: "§aHarvestcraft!§r is an Add-On created by §6Some Game Studios§r\n\nFollow us on Twitter! §o§6@somegamestudio_§r\n\nWant to reach out? Contact us at §o§6hello@somegamestudio.co.uk§r!",
        buttons: [
            {
                title: "Return",
                icon:  "textures/sgs/farm/items/icons/icon_return",
                connectID: "sgs_farm:main"
            },
        ],
        type: "form",
        openOnBlock: ""
    }
];

guideBookListeners();

function openMenu(player, menuID)
{
    player.playSound(SOUND_TURN_PAGE, SOUND_OPTIONS);

    const menu_data = MENUS.find((f) => f.menuID == menuID);
    if (menu_data == undefined) return;

    const menu = new ui.ActionFormData();
    menu.title(menu_data.title);
    menu.body(menu_data.body);
    menu_data.buttons.forEach((button) => {
        menu.button(button.title, button.icon);
    });

    menu.show(player).then(result => {
        if (result.canceled) return;

        let response = result.selection;
        openMenu(player, menu_data.buttons[response].connectID);
    });
}

function guideBookListeners() {
    //drop guidebook on player first spawn only
    mc.world.afterEvents.playerSpawn.subscribe((eventData) => {
        if (eventData.player.hasTag('sgs_farm_book')) { }
        else {
            mc.world.getDimension(eventData.player.dimension.id).spawnItem(new mc.ItemStack("sgs_farm:guidebook", 1), eventData.player.location);
            eventData.player.addTag('sgs_farm_book');
        }
    })

    //guidebook activation listener
    mc.world.afterEvents.itemUse.subscribe((eventData) => {
        let player = eventData.source;
        let itemUse = eventData.itemStack;
        if (itemUse === undefined) return;
        if (itemUse.typeId == "sgs_farm:guidebook") openMenu(player, "sgs_farm:main");
    })
}