import {
    system
} from "@minecraft/server";

import {
    world,
    ItemTypes
} from '@minecraft/server'

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

system.beforeEvents.watchdogTerminate.subscribe(e => {
    e.cancel = true
    console.warn(e.terminateReason)
})

function showChanges(player){
  system.run((run) => {
    const form = new ActionFormData()
        .title("news_text.name")
        .body("news2_text.name")
        .button("close_text.name")
    form.show(player).then(response => {
        if (!response.isCanceled) {
            if (response.selection == 0){
                player.addTag("")
                player.addTag("")
            }
            else if (response.selection == 1){
                player.addTag("")
                player.addTag("")
            }
        }
    })
 })
}

world.beforeEvents.itemUse.subscribe(v=> {
    if (v.itemStack.typeId == "furnicraft:info_book"){
        if (v.source.hasTag("InfoBook")) {
            showChanges(v.source)
        }
        else{
          
            showChanges(v.source)
        }
    }
})