import { Player } from "@minecraft/server";
import { config, sendPlayerMessage } from "../../../config";
import { lifesteal } from "../../../lifesteal";
import { Command } from "../../handler";

export function compatibilityHelp(player: Player) {
    sendPlayerMessage(player, `§e§lLifesteal Help Page -- compatibility§r§6
> Set addon compatibility with other mods, by enabling these options, they will remove certain lifesteal features but enable for lifesteal to be used with other mods

> Usage: ${config.prefix}compatibility <option> <true/false>

> Args: [
    useplayerjson - Whether to use player.json, turning this off will enable a backup heart system which is scuffed but works
    antilore - Turns item lore off when enabled, allowing for compatibility with anti-cheats with a lore check
]

> Examples: [
    ${config.prefix}compatibility
    ${config.prefix}compatibility useplayerjson
    ${config.prefix}compatibility antilore true
]`);
}

new Command({
    name: `compatibility`,
    staffOnly: true,
    code({ player, args }) {
        if (!args[0]) {
            return compatibilityHelp(player);
        }

        switch (args.shift()) {
            case `antilore`:
                if (!args[0]) return sendPlayerMessage(player, `§aantiLore is set to §f${lifesteal.get(`antilore`)}`);

                if (![`true`, `false`].includes(args[0].toLowerCase())) return sendPlayerMessage(player, `§8[§cX§8] §cMust be true or false`);
                lifesteal.set(`antilore`, args[0].toLowerCase());

                sendPlayerMessage(player, `§8[§a/§8] §aSet antiLore to §f${args[0]}`);
                break;
            case `useplayerjson`:
                if (!args[0]) return sendPlayerMessage(player, `§ausePlayerJson is set to §f${lifesteal.get(`useplayerjson`)}`);

                if (![`true`, `false`].includes(args[0].toLowerCase())) return sendPlayerMessage(player, `§8[§cX§8] §cMust be true or false`);
                lifesteal.set(`useplayerjson`, args[0].toLowerCase());

                sendPlayerMessage(player, `§8[§a/§8] §aSet usePlayerJson to §f${args[0]}`);
                break;
        }
    },
});