import { system, world } from '@minecraft/server';
import { ChestFormData } from './extensions/forms';
import { ActionFormData } from '@minecraft/server-ui';
function Mibrowser(player) {
const form = new ChestFormData('large')
.title("Menu: Mi Browser's")
.button(10, 
'§l§7Item Explore: Weapon §9(Available Pages)', 
[
'§r§8  ',
'§r§8  §e»§f Showing All Custom Weapon',
'§r§8  §e»§7 Like Providing All Weapon Brutal Legend',
'§r§8  §e»§f And here there are no restrictions on taking weapon',
'§r§8  ',
'§r§8  Click me to go to the menu'
],'textures/items/iron_sword')
.button(11, 
'§l§7Item Explore: Cosmetic §9(Available Pages)', 
[
'§r§8  ',
'§r§8  §e»§f Showing All Custom Cosmetics',
'§r§8  §e»§7 Like Providing All Weapon Brutal Legend',
'§r§8  §e»§f And here there are no restrictions on taking Cosmetics',
'§r§8  ',
'§r§8  Click me to go to the menu'
],'textures/items/diamond_chestplate')
.pattern([
'_________', // 0 1 2 3 4 5 6 7 8
'______a__', // 9 10 11 12 13] 14 15 16 17
'______a__', // 18 19 20 21 22 23 24 25 26
'______a__', // 27 28 29 30 31 32 33 34 35
'______a__', // 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' },
});
form.show(player).then(response => {
if (response.canceled) return;
if (response.selection === 49) {
player.runCommand(`tellraw @s {"rawtext":[{"text":"§aLeft"}]}`);
} else if (response.selection === 10) { 
player.runCommand(`tag @s add sl_page_1`);
} else if (response.selection === 11) { 
player.runCommand(`tag @s add sl_page_2`);
} else {
player.runCommand(`tag @s add Mibrowser`);
}
}).catch(error => {
player.runCommand(`tellraw @s {"rawtext":[{"text":"§4Error: ${error.message}"}]}`);
});
}
system.runInterval(() => {
for (let player of world.getPlayers()) {
if (player.hasTag("Mibrowser")) {
Mibrowser(player);
player.removeTag("Mibrowser");
}
}
}, 20);
world.afterEvents.itemUse.subscribe(evd => {
if (evd.itemStack.typeId !== 'custom:sl_menu') return;
Mibrowser(evd.source);
});