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

/**
 * Evento del componente plasmaDrillSwichModeComponent
 * @param {{blockFace: string, source: Player, usedOnBlockPermutation: BlockPermutation, itemStack: ItemStack, 
 * faceLocation: {x: number, y: number, z: number}, block: Block}} event 
 */
export const plasmaDrillSwichModeEvent = ({ blockFace, source, usedOnBlockPermutation, itemStack, faceLocation, block }) => {
    const state = source.getDynamicProperty('nps_ec:drill');


    if (itemStack.typeId == "nps_ec:plasma_drill") {
        if (state == undefined) {
            source.setDynamicProperty('nps_ec:drill', 1);
            source.runCommand("playsound plastic.switch.2 @a [r=5] ~ ~ ~ 0.3");
            setLoreItem(itemStack, source, "§r§9Damage area", 'Drill in multiblock mode');
            return
        };

        if (state) {
            source.setDynamicProperty('nps_ec:drill', 0);
            source.runCommand("playsound plastic.switch.1 @a [r=5] ~ ~ ~ 0.3");

            setLoreItem(itemStack, source, "§r§9+18", 'Drill in single block mode');
        } else {
            source.setDynamicProperty('nps_ec:drill', 1);
            source.runCommand("playsound plastic.switch.2 @a [r=5] ~ ~ ~ 0.3");

            setLoreItem(itemStack, source, "§r§9Damage area", 'Drill in multiblock mode');
        }
    } else {
        if (state == undefined) {
            source.setDynamicProperty('nps_ec:drill', 1);
            source.runCommand("playsound plastic.switch.2 @a [r=5] ~ ~ ~ 0.3");
            setLoreItem(itemStack, source, "§r§9Damage area", 'Drill in multiblock mode', "§r§7Disabled");
            return
        };

        if (state) {
            source.setDynamicProperty('nps_ec:drill', 0);
            source.runCommand("playsound plastic.switch.1 @a [r=5] ~ ~ ~ 0.3");

            setLoreItem(itemStack, source, "§r§9+0", 'Drill in single block mode', "§r§7Disabled");
        } else {
            source.setDynamicProperty('nps_ec:drill', 1);
            source.runCommand("playsound plastic.switch.2 @a [r=5] ~ ~ ~ 0.3");

            setLoreItem(itemStack, source, "§r§9Damage area", 'Drill in multiblock mode', "§r§7Disabled");
        }
    }
}