import { world, EquipmentSlot } from "@minecraft/server";

// Ice Wand
export function SwordMechanicWand() {
    world.afterEvents.itemUse.subscribe(({ source }) => {
        const equippable = source.getComponent("equippable");
        const item = equippable.getEquipment(EquipmentSlot.Mainhand);
        if (!item) return;
        switch (item.typeId) {
            case "morellager:ice_wand": // Wand
                if (item.typeId === "morellager:ice_wand" && !source.hasTag('cooldown_sword_basic') && source.isOnGround) {
                    source.runCommandAsync('function wands/ice_wand');
                    source.addTag('cooldown_sword_basic');
                    break;
                }

        }
    });
}

// Lightning Wand
export function SwordMechanicWandL() {
    world.afterEvents.itemUse.subscribe(({ source }) => {
        const equippable = source.getComponent("equippable");
        const item = equippable.getEquipment(EquipmentSlot.Mainhand);
        if (!item) return;
        switch (item.typeId) {
            case "morellager:lightning_wand": // Wand
                if (item.typeId === "morellager:lightning_wand" && !source.hasTag('cooldown_sword_basic') && source.isOnGround) {
                    source.runCommandAsync('function wands/lightning_wand');
                    source.addTag('cooldown_sword_basic');
                    break;
                }

        }
    });
}

// Regen Wand
export function SwordMechanicWandR() {
    world.afterEvents.itemUse.subscribe(({ source }) => {
        const equippable = source.getComponent("equippable");
        const item = equippable.getEquipment(EquipmentSlot.Mainhand);
        if (!item) return;
        switch (item.typeId) {
            case "morellager:regen_totem_hand": // Wand
                if (item.typeId === "morellager:regen_totem_hand" && !source.hasTag('cooldown_sword_basic') && source.isOnGround) {
                    source.runCommandAsync('function wands/wand_health');
                    source.addTag('cooldown_sword_basic');
                    break;
                }

        }
    });
}

// Wind Staff
export function SwordMechanicWind() {
    world.afterEvents.itemUse.subscribe(({ source }) => {
        const equippable = source.getComponent("equippable");
        const item = equippable.getEquipment(EquipmentSlot.Mainhand);
        if (!item) return;
        switch (item.typeId) {
            case "morellager:staff_of_wind": // Wand
                if (item.typeId === "morellager:staff_of_wind" && !source.hasTag('cooldown_sword_basic') && source.isOnGround) {
                    source.runCommandAsync('function wands/staff_of_wind');
                    source.addTag('cooldown_sword_basic');
                    break;
                }

        }
    });
}