import { ActionFormData } from "@minecraft/server-ui";
import { ItemStack } from "@minecraft/server";
import { NAMESPACE } from "./anvilConstants";
export function wikiDinoInteractEvent(eventData) {
    const p = eventData.source;
    const item = eventData.itemStack;
    if (item.typeId === `${NAMESPACE}:wikidino_book`) {
        wikiDino(p);
    }
}
function wikiDino(p) {
    try {
        let form = new ActionFormData()
            .title({ rawtext: [{ translate: `${NAMESPACE}.wikidino.title` }] })
            .button({ translate: `${NAMESPACE}.wikidino.title_passive` }, "textures/hf_da/dinos_addon/ui/wikidino/passive.png")
            .button({ translate: `${NAMESPACE}.wikidino.title_neutral` }, "textures/hf_da/dinos_addon/ui/wikidino/neutral.png")
            .button({ translate: `${NAMESPACE}.wikidino.title_aggressive` }, "textures/hf_da/dinos_addon/ui/wikidino/aggressive.png")
            .button({ translate: `${NAMESPACE}.wikidino.title_all` }, "textures/hf_da/dinos_addon/ui/wikidino/all.png");

        form.show(p).then((response) => {
            const inv = p.getComponent("inventory").container;
            const heldItem = inv.getItem(p.selectedSlotIndex);
            if (response.selection === 0) {
                if (heldItem?.typeId === `${NAMESPACE}:wikidino_book`) {
                    const newItem = new ItemStack(`${NAMESPACE}:wikidino_book2`, 1);
                    inv.setItem(p.selectedSlotIndex, newItem);
                }
            }
            if (response.selection === 1) {
                if (heldItem?.typeId === `${NAMESPACE}:wikidino_book`) {
                    const newItem = new ItemStack(`${NAMESPACE}:wikidino_book3`, 1);
                    inv.setItem(p.selectedSlotIndex, newItem);
                }
            }
            if (response.selection === 2) {
                if (heldItem?.typeId === `${NAMESPACE}:wikidino_book`) {
                    const newItem = new ItemStack(`${NAMESPACE}:wikidino_book4`, 1);
                    inv.setItem(p.selectedSlotIndex, newItem);
                }
            }
            if (response.selection === 3) {
                if (heldItem?.typeId === `${NAMESPACE}:wikidino_book`) {
                    const newItem = new ItemStack(`${NAMESPACE}:wikidino_book5`, 1);
                    inv.setItem(p.selectedSlotIndex, newItem);
                }
            }
        });
    } catch (e) { }
}