import { world, Player, system, ItemStack, Vector } from "@minecraft/server";
import { ActionFormData, ModalFormData } from "@minecraft/server-ui";
import { sendPlayerMessage, sendAllMessage, config } from "../../config";
import { deadplayers, lifesteal, lifestealVersion, revivelist } from "../../lifesteal";

system.runInterval(() => {
    for (let player of world.getAllPlayers()) {
        if (!player.hasTag(`welcome-gui_done`)) {
            player.addTag(`welcome-gui_done`);
            function form(player: Player) {
                const welcomeGui = new ActionFormData()
                    .title(`Welcome to lifesteal!`)
                    .body(`§gWelcome! This world has the §6Lifesteal Addon§g installed!\nThis lifesteal addon was created by §1§lGamerDos§r§g on §fYou§cTube§g, check him out!\n\n§lDo ${config.prefix}help to see all commands`)
                    .button(`Next`, `textures/ui/arrow.png`);
                welcomeGui.show(player).then(result => {
                    if (result.canceled) return form(player);
                    if (result.selection == 0) {
                        player.playSound(`random.orb`);
                        function nextForm(player: Player) {
                            const welcomeGui2 = new ActionFormData()
                                .title(`Lifesteal message`)
                                .body(`§gI will only post this addon to §amcpedl.com and modbay, not any other site§g, if you downloaded this addon from another site, like the §aGoogle Play Store, 9minecraft.com, mc-addons.com, minecraft-pocket.com, etc, then you have an unofficial version of the addon§g, and you should report whoever posted it there, enjoy the addon! :D`)
                                .button(`Accept and close`, `textures/ui/check.png`)
                                .button(`Read me if you're showcasing\nthis addon on YT`, `textures/items/map_filled.png`)
                                .button(`Lifesteal Changelogs`, `textures/items/map_filled.png`);
                            welcomeGui2.show(player).then(result => {
                                if (result.selection == 0) {
                                    player.playSound(`random.levelup`);
                                    sendPlayerMessage(player, `§e- dsc.gg/gamerdos: §6GamerDos' Discord Server (Join if you need help or you have a question)\n\n§e- mcpedl.com/lifesteal-addon: §6The MCPEDL page, check up on this for updates\n\n§e- patreon.com/gamerdos: §6Support what I do!`);
                                    return;
                                }
                                if (result.canceled) return nextForm(player);

                                if (result.selection == 1) {
                                    player.playSound(`random.orb`, { pitch: 1.1 });
                                    let readMe = new ActionFormData()
                                        .title(`ReadMe`)
                                        .body(`§g• I'd appreciate if you don't give the direct link to the addon and link the MCPEDL page (https://mcpedl.com/lifesteal-addon) as the direct link will not update automatically, also, by linking the direct link, people won't know how to use the addon unless you showcase every last feature, I'd also appreciate if you give credit in the video and not just throw me down in the description since almost nobody reads them, thanks!`)
                                        .button(`Back`, `textures/ui/arrow_left.png`);
                                    readMe.show(player).then(() => {
                                        nextForm(player);
                                    });
                                }

                                if (result.selection == 2) {
                                    player.playSound(`random.orb`, { pitch: 1.15 });
                                    let changelog = `§e${lifestealVersion}§6
• Updated jumpscare command
• Updated to 1.20.70
• Reviving someone without a spawnpoint no longer shows a death message
• Withdraw no longer shows a give message

§e1.15.1-release§6
• Fixed revive system
• New command: ?heart notify
• New help menu

§eLifesteal 1.15.0-release§6
• Made compatible with 1.20.60
• New commands
• - ?compatibility
• - ?heart gain
• - ?heart lose
• - ?heart count
• New textures for all the items
• Heart of Life is no longer the revive item, it is now the Beacon of Life
• Heart of Life given a different use
• Heart of Life given an animation
• Code improved
• Bug fixes

§eLifesteal 1.15.0-beta§6
• Added 1.20.40 support
• Added new customization options!
- New ?lifesteal mode command
- New subcommands to ?heart
= ?heart gain - Sets the amount of hearts gained when killing a player
= ?heart lose - Sets the amount of hearts lost when dying ${lifesteal.get(`envsteal`) === true ? `from a player` : ``}
• Fixed lifesteal items spamming console
• Fixed lore bug
• Fixed recipe bug

§eLifesteal 1.14.5-release§6
• Bug fixes

§eLifesteal 1.14.3-release§6
• Made addon comaptible with 1.20.10
• Bug fixes
• Other stuff I prob forgot

§eLifesteal 1.14.2-release§6
• Fixed item lore bug
• Bug fixes

§eLifesteal 1.14.2-release§6
• Improved backend code
• Slight performance improvements
• Made it so only people who have lifesteal-opped or are opped can use ?op (i forgot to make it staff only.. oops)
• Minor bug fixes

§eLifesteal 1.14.0-release§6
• Added 1.20.x support
• Overhauled the revive and dead systems
• Made the heart system a lot better (a lot)
• Changed the command system to work in 1.20.x
• Rewrote the ?heart command (Now more better code and readable)
• Added back ?heart reset
• New ?heart set, add, remove, display, and show syntax
• Slight texture changes
• Added new commands:
- ?reviveamount <amount> - How many hearts to give a player when they get revived
- ?startamount <amount> - How many hearts to give a player when they first join the world/server/realm/etc
• New syntaxes:
- ?heart display
- ?heart show
- ?heart set GamerDos7511 10
- ?heart add "Gamer Dos23" 10
- ?heart remove "GamerDos7511" 10
• Moved ?heart heartgl to its own command, now its just ?heartgl
• When you are at max health and you gain a heart, you will stay at your previous health (e.g you are at 10 hearts, you gain a heart, you stay at 10 health and your max health is now 11)
• Made the revive and dead players system better
• The addon now checks if HCF is off (Holiday Creator Features)
• A lot of performance changes/improvements
• Rewrote A LOT of the code and made it better
• Fixed the bug where the ghosts can use ?heart display and ?heart show
• Changed the color of help page to green
• New database (Less ram usage hopefully)
• Bug fixes
• Other stuff I probably forgot to put here`;

                                    let changeLogsGui = new ActionFormData()
                                        .title(`Lifesteal Changelog`)
                                        .body(`§gLifesteal Changelog\n${changelog}`)
                                        .button(`Back`, `textures/ui/arrow_left.png`);
                                    changeLogsGui.show(player).then(() => {
                                        nextForm(player);
                                    });
                                }
                            });
                        }
                        nextForm(player);
                    }
                });
            }
            form(player);
        }
    }
}, 1);