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

// first page
function showMainUI(player) {
    const ui = new ActionFormData()
        .title("notebook.title")
        .body("notebook.body")
        .button("notebook.beater", "textures/ui/beater")
        .button("notebook.fermenter", "textures/ui/fermenter")
        .button("notebook.freezer", "textures/ui/freezer")
        .button("notebook.fryingpan", "textures/items/frying_pan")
        .button("notebook.pasteurizer", "textures/ui/pasteurizer")
        .button("notebook.pestle", "textures/ui/pestle")
        .button("notebook.plate", "textures/items/plate")
        .button("notebook.saucepan", "textures/items/saucepan")
        .button("notebook.teapot", "textures/ui/teapot")
        .button("notebook.toaster", "textures/ui/toaster");

    ui.show(player).then(response => {
        if (response.canceled) return;

        switch (response.selection) {
            case 0:
                showDossierUI(player, "notebook.beater", "description.beater");
                break;
            case 1:
                showDossierUI(player, "notebook.fermenter", "description.fermenter");
                break;
            case 2:
                showDossierUI(player, "notebook.freezer", "description.freezer");
                break;
            case 3:
                showDossierUI(player, "notebook.fryingpan", "description.fryingpan");
                break;
            case 4:
                showDossierUI(player, "notebook.pasteurizer", "description.pasteurizer");
                break;
            case 5:
                showDossierUI(player, "notebook.pestle", "description.pestle");
                break;
            case 6:
                showDossierUI(player, "notebook.plate", "description.plate");
                break;
            case 7:
                showDossierUI(player, "notebook.saucepan", "description.saucepan");
                break;
            case 8:
                showDossierUI(player, "notebook.teapot", "description.teapot");
                break;
            case 9:
                showDossierUI(player, "notebook.toaster", "description.toaster");
                break;
        }
    });
}

// machine pages
function showDossierUI(player, title, dossier) {
    const ui = new ActionFormData()
        .title(title)
        .body(dossier)
        .button("button.back");

    ui.show(player).then(response => {
        if (response.canceled) return;
        showMainUI(player);
    });
}

// exposes the archive
globalThis.openNotebookUI = showMainUI;