import { ActionFormData, MessageFormData } from "mojang-minecraft-ui"
import { world } from "mojang-minecraft"

/*
 * Import 
 */



 world.events.beforeItemUse.subscribe(data => {
    let { item, source } = data
    const player = data.source
    if (item.id == "mmp:start") {  // Item.id is set to dirt currently you can change to any item
      ui(player)
    }
  })

/**
 * Show the ui to the player
 * @param {player} player Player to show the ui to
 */

// Page 1

function ui(player) {
    let form = new ActionFormData()
        form.title("§0Island Chooser") // Title of the GUI
   //     form.body("Choose Island") // Body Text Of the GUI
        form.button("Vanilla", "textures/island/vanilla") // Button 1 Text
        form.button("§aCustom", "textures/island/custom") // Button 2 Text
        form.button("§4Japanese", "textures/island/japanese")
        form.button("§6Nether", "textures/island/nether") // Button 3 Text
        form.button("§8End", "textures/island/end")
form.button("§2Jungle", "textures/island/bamboo")
form.button("§gBees", "textures/island/bee")
form.button("§7Cave", "textures/island/cave")
form.button("§eLuckyblock", "textures/island/luckyblock")


        form.show(player).then((response) => {
        if (response.selection === 0) {
            player.runCommand(`function choose/vanilla`);  // Runs A command on the player
    }
        if (response.selection === 1) {
            player.runCommand(`function choose/custom`)
    }
           if (response.selection === 2) {
            player.runCommand(`function choose/japanese`)
    }
         if (response.selection === 3 ) {
             player.runCommand(`function choose/nether`)
    }
       if (response.selection === 4) { 
             player.runCommand('function choose/end')
             
    }
     if (response.selection === 5) { 
             player.runCommand('function choose/bamboo')
             
    }
     if (response.selection === 6) { 
             player.runCommand('function choose/bee')
             
    }
     if (response.selection === 7) { 
             player.runCommand('function choose/cave')
             
    }
     if (response.selection === 8) { 
             player.runCommand('function choose/luckyblock')
             
    }
    
 /*   if(response.selection == 3) return page2(player) // Returns a Second Page to a Player */
        })
    }

// Page 2

function page2(player) {
    let temp = new MessageFormData()
        temp.title("GUI Menu Template 2/2")
        temp.body("Created by LVRAID3RS#4808")
        temp.button1(`Confirm`) // Unforunately 'MessageFormData' Can only have 2 button i Suggest using 'ActionFormData'
        temp.button2(`Cancel`) // Cancels out the UI

        
        temp.show(player).then((response) => {  
            if (response.selection === 1) { // ActionFormData GUI's start from 0 While Messageformdata starts at 1
                player.runCommand(`say Pressed Confirm Button`);
            }
        })
    }