import { system, world } from '@minecraft/server';
import { ChestFormData } from './extensions/forms';
import { ActionFormData } from '@minecraft/server-ui';

system.runInterval(() => {
for (let player of world.getPlayers()) {
if (player.hasTag("sl_page_2")) {
sl_page_2(player);
player.removeTag("sl_page_2");
}
}
}, 20);

function sl_page_2(player) {
const form = new ChestFormData('large')
.title('Item Explore: Cosmetic {1/1}')

.button(10, '§bWings', 
[
'§r§7  §7Protection§8:§f 4',  
'§r§8minecraft:diamond_chestplate',  
'§r§8NBT: 23 tag(s)',
'§a Click Me to take'
],
'textures/items/soul_demonic_wing')

.button(19, '§bHorn', 
[
'§r§7  §7Protection§8:§f 4',  
'§r§8minecraft:diamond_helmet',  
'§r§8NBT: 27 tag(s)',
'§a Click Me to take'
],
'textures/items/soul_demonic_horn')

// Button Fungsional

.button(49, 
'§l§bReturn to Mi Browser Menu', 
[
'§r§8  ',
'§r§8  Click me to go to Mi Browser'
],
'textures/items/arrow')

.button(47, 
'§l§aInfo Sl Ui menu', 
[
'§r §e>§7 Click One Weapon to Take It',
' §e>§f When you click it, Weapon will be in your inventory',
' §e>§7 Enjoy!!!',
'',
 ' §e> §7 Credits:',
'§r  >§7 Creator',
'§r',
'§r  >§f Addons Weapon By @Dyfrii',
'§r  >§7 Addons Scripts UI Chest Menu By @VelixsCraftMCYT'
],
'textures/items/cauldron')

.button(51, '§9<{ §dSl Page All menu List §9}>', 
[
'§r§8  §e> §fDisplay All Weapon Menu Pages Easily',
'§r§8  ',
'§r§8  Click me to Open Page menu all page list'
],
'textures/items/book_enchanted')

.pattern([
'_________', // 0 1 2 3 4 5 6 7 8
'__aaaaaa_', // 9 10 11 12 13 [14 15 16] 17
'__aaaaaa_', // 18 [19] 20 21 22 23 24 25 26
'_aaaaaaa_', // 27 28 29 30 31 32 33 34 35
'_________', // 36 37 38 39 40 41 42 43 44
'_________', // 45 46 47 48  49  50 51 52 53
], {
a: { itemName: '§f', enchanted: false, stackAmount: 1, texture: 'textures/blocks/glass_gray' },
e: { itemName: '§f', enchanted: false, stackAmount: 1, texture: 'textures/blocks/glass_white' },
p: { itemName: '§f', enchanted: false, stackAmount: 1, texture: 'textures/blocks/glass_white' },
n: { itemName: '§f', enchanted: false, stackAmount: 1, texture: 'textures/blocks/glass_white' },
});

form.show(player).then(response => {
if (response.canceled) return;
if (response.selection === 49) {
player.runCommand(`tag @s add Mibrowser`);
} else if (response.selection === 10) {
player.runCommand(`tellraw @s {"rawtext":[{"text":"§8<§bServer§8>§a You've got it"}]}`);
player.runCommand(`summon lore:soul1`);
} else if (response.selection === 19) {
player.runCommand(`tellraw @s {"rawtext":[{"text":"§8<§bServer§8>§a You've got it"}]}`);
player.runCommand(`summon lore:soul2`);

} else if (response.selection === 18) {
player.runCommand(`tag @s add sl_page_2`);
} else if (response.selection === 47) {
player.runCommand(`tag @s add sl_page_list`);
} else if (response.selection === 51) {
player.runCommand(`tag @s add sl_page_list`);

} else {
player.runCommand(`tag @s add sl_page_2`);
}
}).catch(error => {
player.runCommand(`tellraw @s {"rawtext":[{"text":"§4Error: ${error.message}"}]}`);
});
}