import * as mc from "@minecraft/server";
import * as lib from "../../../lib"
export const itemStack = {
    typeId: "ld_eb:earth_glove"
}
export class ItemSkills {
    /**
     * @param { mc.ItemStack } item - O item que o jogador esta segurando.
     * @param { mc.Player } player - O jogador que esta segurando o item.
     */
    constructor(item, player) {
        this.item = item
        this.player = player
        // start system
        if (!player.getDynamicProperty(item.typeId + ".init")) {
            player.setDynamicProperty(item.typeId + ".init", true)
            // level system
            player.setDynamicProperty(item.typeId + ".lvl", 0)
            player.setDynamicProperty(item.typeId + ".xp", 0)
            player.setDynamicProperty(item.typeId + ".xpm", 10)
            // ultimate system
            player.setDynamicProperty(item.typeId + ".ult", 0)
            //console1-console.warn("propriedades iniciadas")
        }
        this.level = player.getDynamicProperty(item.typeId + ".lvl")
        this.xp = player.getDynamicProperty(item.typeId + ".xp")
        this.xpm = player.getDynamicProperty(item.typeId + ".xpm")
        this.ult = player.getDynamicProperty(item.typeId + ".ult")
    }
    /**
     * Função chamada antes do jogador pegar o item.
     * @memberof ItemSkills
     */
    before() {
        /** @type { mc.Player } */
        const player = this.player,
            /** @type { mc.ItemStack } */
            item = this.item
            startAnimations(player)
        this.interface()
    }
    interface() {
        /** @type { mc.Player } */
        const player = this.player,
            /** @type { mc.ItemStack } */
            item = this.item
    
        // Function to create a progress bar
        const createProgressBar = (current, max, color = "§a") => {
            const lenght = 25
            const filledLength = Math.floor((current / max) * lenght)
            const emptyLength = lenght - filledLength
            return color + ":".repeat(filledLength) + "§7:".repeat(emptyLength)
        }
    
        if (this.level < 10) {
            const xpBar = createProgressBar(this.xp, this.xpm);
            let actionBarText = `§7Lv. §f${this.level}: §7${xpBar} §f${this.xp}§7/${this.xpm}`;
        
            if (this.level >= 5) {
                const ultBar = createProgressBar(this.ult, 10);
                actionBarText += `\n§eUltimate: §7${ultBar} §r${this.ult}§7/10`;
            }
        
            player.onScreenDisplay.setActionBar(actionBarText);
        } else {
            if (this.ult < 10) {
                const ultBar = createProgressBar(this.ult, 10);
                player.onScreenDisplay.setActionBar(
                    `§7Lv. 10 (Max)\n§eUltimate: §7${ultBar} §r${this.ult}§7/10`
                );
            } else {
                player.onScreenDisplay.setActionBar(
                    `§7Lv. 10 (Max)\n§eUltimate Ready!`
                );
            }
        }
    }
    /**
     * Função chamada quando o item está na mão do jogador.
     * @memberof ItemSkills
     */
    repeat() {
        /** @type { mc.Player } */
        const player = this.player,
            /** @type { mc.ItemStack } */
            item = this.item
    }
    /**
     * Função chamada quando o jogador solta o item.
     * @memberof ItemSkills
     */
    after() {
        /** @type { mc.Player } */
        const player = this.player,
            /** @type { mc.ItemStack } */
            item = this.item
    }
}
export const startAnimations = (player, animation, id) => {
    if (!mc.world.getDynamicProperty("ld_eb:animations")) return
    lib.animation(player, "animation.ld_eb_earth_glove.tpp_idle_player", itemStack.typeId, 2, true)
}