import { pokemonUtils } from "../utils/pokemonUtils.js";
import { EntityComponentTypes } from "@minecraft/server";
import { StringUtils } from "../utils/stringUtils.js";
export const ITEMS_UI = {
    "pr:arceus_phone": {},
    "pr:revive": {},
    "pr:revival_herb": {},
    "max_revive": {}
};
export const INITIALIZED_ITEMS_DATA = {
    "pr:arceus_phone": {
        amount: 1
    },
    "pr:potion": {
        amount: 1
    },
    "pr:pokeball": {
        amount: 10
    },
};
export const ITEMS_INTERACT_WITH_POKEMON = {
    "pr:potion": {
        fn: (itemStack, target, player, managerInventory) => {
            healedPokemon(target, player, itemStack, managerInventory, 20);
        }
    },
    "pr:rare_candy": {
        fn: (itemStack, target, player, managerInventory) => {
            const level = target.getDynamicProperty("pr:level");
            const nickName = target.getDynamicProperty("pr:nickname");
            if (!level)
                return;
            target.setDynamicProperty("pr:level", level + 1);

            // sync level to slot save data so it persists + HUD updates after relog
            try {
                const slotIndex = (player.getDynamicProperty("pr:sended_pokemon_slot") ?? player.getDynamicProperty("pr:selectedSlot") ?? 1) - 1;
                if (slotIndex >= 0) {
                    const slotData = pokemonUtils.getPokemonFromSlot(player, slotIndex);
                    if (slotData) {
                        slotData.level = level + 1;
                        pokemonUtils.updatePokemonSlot(player, slotIndex, slotData);
                    }
                    player.setDynamicProperty(`pr:slot_${slotIndex + 1}_level`, level + 1);
                }
            } catch (e) { console.warn(e); }

            if (!nickName || nickName === "none") {
                target.nameTag = StringUtils.toTitleCaseEntityName(target.typeId) + " | Lvl: §a" + target.getDynamicProperty("pr:level") + "§r\n" + "Owner:§a " + target.getDynamicProperty("pr:owner_name");
            }
            else {
                target.nameTag = target.getDynamicProperty("pr:nickname") + " | Lvl: §a" + target.getDynamicProperty("pr:level") + "§r\n" + "Owner:§a " + target.getDynamicProperty("pr:owner_name");
            }
            player.playSound("random.orb");
            player.onScreenDisplay.setActionBar("Level up!");
        }
    },
    "pr:super_potion": {
        fn: (itemStack, target, player, managerInventory) => {
            healedPokemon(target, player, itemStack, managerInventory, 60);
        }
    },
    "pr:hyper_potion": {
        fn: (itemStack, target, player, managerInventory) => {
            healedPokemon(target, player, itemStack, managerInventory, 120);
        }
    },
    "pr:max_potion": {
        fn: (itemStack, target, player, managerInventory) => {
            healedPokemon(target, player, itemStack, managerInventory, 800);
        }
    },
    "pr:full_restore": {
        fn: (itemStack, target, player, managerInventory) => {
            const health = target.getComponent(EntityComponentTypes.Health);
            if (!health)
                return;
            healedPokemon(target, player, itemStack, managerInventory, health.defaultValue);
        }
    },
    "pr:fresh_water": {
        fn: (itemStack, target, player, managerInventory) => {
            healedPokemon(target, player, itemStack, managerInventory, 30);
        }
    },
    "pr:soda_pop": {
        fn: (itemStack, target, player, managerInventory) => {
            healedPokemon(target, player, itemStack, managerInventory, 50);
        }
    },
    "pr:lemonade": {
        fn: (itemStack, target, player, managerInventory) => {
            healedPokemon(target, player, itemStack, managerInventory, 80);
        }
    },
    "pr:moomoo_milk": {
        fn: (itemStack, target, player, managerInventory) => {
            healedPokemon(target, player, itemStack, managerInventory, 100);
        }
    },
    "pr:berry_juice": {
        fn: (itemStack, target, player, managerInventory) => {
            healedPokemon(target, player, itemStack, managerInventory, 20);
        }
    },
    "pr:energy_powder": {
        fn: (itemStack, target, player, managerInventory) => {
            healedPokemon(target, player, itemStack, managerInventory, 60);
        }
    },
    "pr:energy_root": {
        fn: (itemStack, target, player, managerInventory) => {
            healedPokemon(target, player, itemStack, managerInventory, 120);
        }
    },
};
export const RANDOM_ITEMS = [
    "pr:pokeball",
    "pr:great_ball",
    "pr:beast_ball",
    "pr:ultra_ball",
    "pr:master_ball",
    "pr:safari_ball",
    "pr:level_ball",
    "pr:lure_ball",
    "pr:moon_ball",
    "pr:friend_ball",
    "pr:love_ball",
    "pr:heavy_ball",
    "pr:net_ball",
    "pr:timer_ball",
    "pr:repeat_ball",
    "pr:premier_ball",
    "pr:nest_ball",
    "pr:dive_ball",
    "pr:luxury_ball",
    "pr:heal_ball",
    "pr:quick_ball",
    "pr:dusk_ball",
    "pr:cherish_ball",
    "pr:dream_ball"
];
export const RANDOM_ITEMS_POKEBALL = [
    "pr:antidote",
    "pr:awakening",
    "pr:berry_juice",
    "pr:burn_heal",
    "pr:elixir",
    "pr:energy_powder",
    "pr:energy_root",
    "pr:ether",
    "pr:fresh_water",
    "pr:full_heal",
    "pr:full_restore",
    "pr:heal_powder",
    "pr:hyper_potion",
    "pr:ice_heal",
    "pr:lemonade",
    "pr:max_elixir",
    "pr:max_ether",
    "pr:max_potion",
    "pr:max_revive",
    "pr:moomoo_milk",
    "pr:paralyze_heal",
    "pr:potion",
    "pr:revival_herb",
    "pr:revive",
    "pr:soda_pop",
    "pr:super_potion",
    "pr:ball_of_mud",
    "pr:scattering_bang",
    "pr:spoiled_apricon",
    "pr:sticky_glob",
    "pr:pokeball",
    "pr:great_ball",
    "pr:beast_ball",
    "pr:ultra_ball",
    "pr:master_ball",
    "pr:safari_ball",
    "pr:level_ball",
    "pr:lure_ball",
    "pr:moon_ball",
    "pr:friend_ball",
    "pr:love_ball",
    "pr:heavy_ball",
    "pr:net_ball",
    "pr:timer_ball",
    "pr:repeat_ball",
    "pr:premier_ball",
    "pr:nest_ball",
    "pr:dive_ball",
    "pr:luxury_ball",
    "pr:heal_ball",
    "pr:quick_ball",
    "pr:dusk_ball",
    "pr:cherish_ball",
    "pr:dream_ball",
    "pr:chicken_key",
    "pr:pokeball_key",
    "pr:pumpkin_key",
    "pr:snow_key",
    "pr:ultra_key",
    "pr:upgrade_key",
    "pr:rare_candy",
    "pr:poke_coin"
];
function healedPokemon(target, player, itemStack, managerInventory, valueHealed) {
    const health = target.getComponent(EntityComponentTypes.Health);
    if (!health)
        return;
    health.setCurrentValue(health.currentValue + valueHealed);
    managerInventory.managerInventory.removeItem(itemStack.typeId, 1);
    player.onScreenDisplay.setActionBar("Healed!");
}
export const POKEBALLS_CAPTURE_RATE = [
    { "pr:pokeball": 1.65 },
    { "pr:great_ball": 1.5 },
    { "pr:beast_ball": 1.0 },
    { "pr:ultra_ball": 2.0 },
    { "pr:master_ball": 255.0 },
    { "pr:safari_ball": 1.5 },
    { "pr:level_ball": 2.0 },
    { "pr:lure_ball": 3.0 },
    { "pr:moon_ball": 4.0 },
    { "pr:friend_ball": 1.0 },
    { "pr:love_ball": 8.0 },
    { "pr:heavy_ball": 4.0 },
    { "pr:net_ball": 3.0 },
    { "pr:timer_ball": 4.0 },
    { "pr:repeat_ball": 3.0 },
    { "pr:premier_ball": 1.0 },
    { "pr:nest_ball": 4.0 },
    { "pr:dive_ball": 3.5 },
    { "pr:luxury_ball": 1.0 },
    { "pr:heal_ball": 1.0 },
    { "pr:quick_ball": 5.0 },
    { "pr:dusk_ball": 3.5 },
    { "pr:cherish_ball": 1.0 },
    { "pr:dream_ball": 255.0 }
];
