import { world, system } from "@minecraft/server";
import { ActionFormData } from "@minecraft/server-ui";

function showKnockbackMenu(player) {
    const form = new ActionFormData()
        .title("§lKnockback Settings")
        .body("Choose your knockback setting:")
        .button("§l§4Remove Kaiju Knockback")  // Normal knockback
        .button("§l§eAdd Kaiju Knockback");   // No knockback

    form.show(player).then((response) => {
        if (response.canceled) return;

        switch (response.selection) {
            case 0:
                // 100% Knockback - Run command
                system.run(() => {
                    player.runCommandAsync("event entity @a minecraft:not_knockback_resistance"); // Removes knockback immunity
                    player.runCommandAsync("say Remove Kaiju Knockback");
                });
                break;
            case 1:
                // 0% Knockback - Run command
                system.run(() => {
                    player.runCommandAsync("event entity @a minecraft:knockback_resistance"); // Gives full knockback immunity
                    player.runCommandAsync("say Add Kaiju Knockback");
                });
                break;
        }
    });
}

world.afterEvents.itemUse.subscribe((event) => {
    const { source, itemStack } = event;
    if (itemStack?.typeId === "gojidraw:knockback_setting") {
        showKnockbackMenu(source);
    }
});