import { Player } from "@minecraft/server";
import { ActionFormData } from "@minecraft/server-ui";
import { RawMessage } from "./RawMessage";

/**
 * @description Crea un componente de vista solo con texto y un botón de regresar
 * @param {Player} player 
 * @param {RawMessage | String} name 
 * @param {RawMessage | String} description 
 * @param {Function} callback
 * @param {String} icon
 */
export const guideViewComponet = (player, name, description, callback, icon = null) => {
    const actionForm = new ActionFormData();
    actionForm.title(name)//Titulo del componente
    actionForm.body(description)//Descripción del componente
    actionForm.button("view.button_return", icon)//Regresar

    actionForm.show(player).then((data) => {
        if (data.canceled) return;
        callback(player);
    })
}


/**
 * @description Crea un componente de vista con texto y un botón de acción
 * @param {Player} player 
 * @param {RawMessage | String} name 
 * @param {RawMessage | String} description 
 * @param {RawMessage | String} buttonViewText
 * @param {Function} buttonViewUnit
 * @param {Function} callback
 * @param {String | null} icon1
 * @param {String | null} icon2
 */
export const guideViewComponetWithButton = (player, name, description, buttonViewText, buttonViewUnit, callback, icon1 = null, icon2 = null) => {
    const actionForm = new ActionFormData();
    actionForm.title(name)//Titulo del componente
    actionForm.body(description)//Descripción del componente
    actionForm.button(buttonViewText, icon1)//Botón del componente
    actionForm.button("view.button_return", icon2)//Regresar

    actionForm.show(player).then((data) => {
        if (data.canceled) return;
        if (data.selection == 0) {
            buttonViewUnit(player);
        } else {
            callback(player);
        }
    })
}