import { EntityComponentTypes, Player } from "@minecraft/server";
import { setLoreItem } from "../../../library/itemManager";

/**
 * Contorla el evento del lore del Plasma Drill
 * @param {Player} player 
 */
export const plasmaDrillLoreEvent = (player) => {
    const equipament = player.getComponent(EntityComponentTypes.Equippable);

    const plasmaDrill = equipament.getEquipment("Mainhand");

    try {
        if (plasmaDrill != null) {
            if (plasmaDrill.typeId.includes("nps_ec:plasma_drill") && plasmaDrill.getLore() == "") {
                const state = player.getDynamicProperty('nps_ec:drill');
                if (plasmaDrill.typeId == "nps_ec:plasma_drill") {
                    if (state == undefined) {
                        player.setDynamicProperty('nps_ec:drill', 0);
                        setLoreItem(plasmaDrill, player, "§r§9+18", 'Drill in single block mode');
                        return
                    };

                    if (state) {
                        player.setDynamicProperty('nps_ec:drill', 0);

                        setLoreItem(plasmaDrill, player, "§r§9+18", 'Drill in single block mode');
                    } else {
                        player.setDynamicProperty('nps_ec:drill', 1);

                        setLoreItem(plasmaDrill, player, "§r§9Damage area", 'Drill in multiblock mode');
                    }
                } else {
                    if (state == undefined) {
                        player.setDynamicProperty('nps_ec:drill', 0);
                        setLoreItem(plasmaDrill, player, "§r§9+0", 'Drill in single block mode', "§r§7Disabled");
                        return
                    };

                    if (state) {
                        player.setDynamicProperty('nps_ec:drill', 0);

                        setLoreItem(plasmaDrill, player, "§r§9+0", 'Drill in single block mode', "§r§7Disabled");
                    } else {
                        player.setDynamicProperty('nps_ec:drill', 1);

                        setLoreItem(plasmaDrill, player, "§r§9Damage area", 'Drill in multiblock mode', "§r§7Disabled");
                    }
                }
            }
        }
    } catch { }
}