import { MinecraftItemTypes } from "../../_Utilities/vanilla-data/mojang-item";
import Upgrade_Form from "../Data/Custom Forms/Upgrade_Form";
import Progression_Manager from "../../Progression/Progression_Manager";
import Entity_Inventory_Manager from "../../Entity/Managers/Entity_Inventory_Manager";
export default class Form_Upgrade_Manager {
    static async load(player) {
        const progression = Progression_Manager.get("07b1d6ae-6288-4d5c-93fb-d10737e6f2c0");
        let amount = 64;
        if (progression.drop_Rate == 20) {
            amount = amount * 2;
        }
        else if (progression.drop_Rate == 40) {
            amount = amount * 4;
        }
        else if (progression.drop_Rate == 60) {
            amount = amount * 8;
        }
        else if (progression.drop_Rate == 80) {
            amount = amount * 8;
        }
        const form = new Upgrade_Form();
        form.title("Upgrade");
        form.view(progression.drop_Rate >= 20 ? "upgrade_1_unlocked" : "upgrade_1_locked");
        form.view("custom_arrow");
        form.view(progression.drop_Rate >= 40 ? "upgrade_2_unlocked" : "upgrade_2_locked");
        form.view("custom_arrow");
        form.view(progression.drop_Rate >= 60 ? "upgrade_3_unlocked" : "upgrade_3_locked");
        form.view("custom_arrow");
        form.view(progression.drop_Rate >= 80 ? "upgrade_4_unlocked" : "upgrade_4_locked");
        form.view("custom_arrow");
        form.view(progression.drop_Rate >= 100 ? "upgrade_5_unlocked" : "upgrade_5_locked");
        if (progression.drop_Rate < 90) {
            form.button("Upgrade");
            form.body("§e" +
                String(amount) +
                "§f Emerald's to upgrade the One Block and increase the double drop rate probability to §e" +
                String(progression.drop_Rate + 20) +
                "§f%%\n\nBlocks Mined: §a" +
                String(progression.blocks_Mined));
        }
        else {
            form.body("One Block at max double drop rate probability\n\nBlocks Mined: §a" + String(progression.blocks_Mined));
        }
        const result = await form.show(player);
        if (result.canceled)
            return;
        const selected = form.buttons[result.selection];
        if (selected == "Upgrade") {
            if (Entity_Inventory_Manager.reduce(player, MinecraftItemTypes.Emerald, amount)) {
                progression.drop_Rate = progression.drop_Rate + 20;
                Progression_Manager.set(progression);
            }
            else {
                player.sendMessage("Not enough emerald's");
            }
        }
    }
}
