import Dialog_Form from "../Data/Custom Forms/Dialog_Form";
export default class Form_Dialog_Manager {
    static async show(player, dialog, index, entity) {
        const form = new Dialog_Form();
        const body = dialog.messages[index];
        form.title(dialog.name);
        form.body(body.replaceAll("{NAME}", player.name));
        if (index != dialog.messages.length - 1) {
            if (index > 0)
                form.button("§cBack§f [§e<§f]");
            form.button("§8Continue§f [§e>§f]");
            form.button("§8Skip§f [§e>>§f]");
        }
        else {
            for (let i = 0; i < dialog.buttons.length; i++) {
                form.button(dialog.buttons[i].text);
            }
        }
        form.texture(dialog.texture);
        const result = await form.show(player);
        if (result.canceled)
            return;
        const selected = form.buttons[result.selection];
        switch (selected) {
            case "§8Continue§f [§e>§f]": {
                this.show(player, dialog, ++index, entity);
                break;
            }
            case "§cBack§f [§e<§f]": {
                this.show(player, dialog, --index, entity);
                break;
            }
            case "§8Skip§f [§e>>§f]": {
                this.show(player, dialog, dialog.messages.length - 1, entity);
                break;
            }
            default: {
                for (let i = 0; i < dialog.buttons.length; i++) {
                    if (selected == dialog.buttons[i].text) {
                        dialog.buttons[i].callback(player, entity);
                    }
                }
                break;
            }
        }
    }
}
