import {
    ActionFormData,
    ModalFormData,
    MessageFormData
} from '@minecraft/server-ui';
import {
    world
} from '@minecraft/server';


world.afterEvents.itemUse.subscribe(({
    itemStack
}) => {
    if (itemStack.typeId == "minecraft:diamond") {
        menu(player)
    }
});


function menu(player) {
    const title = "My Slider";
    const minValue = 0;
    const maxValue = 3;
    const valueStep = 1;
    const defaultValue = 0;
    const form = new ModalFormData()
    .title("Example")
    .textField("Your effect",
        "effect")
    .slider(title,
        minValue,
        maxValue,
        valueStep,
        defaultValue)
    .toggle("test")
    .dropdown("timer", [10, 20, 30, 40, 50], 0)
    .show(player).then(({
        formValues
    }) => {
        const [effect,
            slider,
            toggle, timer] = formValues;
            player.runCommandAsync(`effect @s ${[effect,
            slider, timer, toggle]}`);
    });
}