package joshie.enchiridion.gui.book.features.recipe;

import joshie.enchiridion.api.EnchiridionAPI;
import joshie.enchiridion.api.recipe.IRecipeHandler;
import net.minecraft.client.Minecraft;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import net.minecraftforge.registries.ForgeRegistries;

import javax.annotation.Nonnull;
import java.util.List;

public class RecipeHandlerFurnace extends RecipeHandlerBase {
    private static WrappedFuelStack fuels;

    public RecipeHandlerFurnace() {
    }

    public RecipeHandlerFurnace(ItemStack output, ItemStack input) {
        stackList.add(new WrappedStack(output, 110D, 32D, 2.5F));
        stackList.add(new WrappedStack(input, 0D, 0D, 2.5F));

        if (fuels == null) fuels = new WrappedFuelStack(0D, 65D, 2.5F);
        stackList.add(fuels);
        addToUnique(ForgeRegistries.ITEMS.getKey(input.getItem()));
    }

    @Override
    public void addRecipes(@Nonnull ItemStack output, List<IRecipeHandler> list, World world) {
        /*Map<ItemStack, ItemStack> smeltingList = FurnaceRecipe.instance().getSmeltingList(); //TODO
        for (ItemStack key : smeltingList.keySet()) {
            ItemStack stack = smeltingList.get(key);
            if (stack.isEmpty()) continue;
            if (stack.isItemEqual(output)) {
                list.add(new RecipeHandlerFurnace(stack, key));
            }
        }*/
    }

    @Override
    public String getRecipeName() {
        return "VanillaFurnace";
    }

    @Override
    public double getHeight(double width) {
        return width * 1.1D;
    }

    @Override
    public double getWidth(double width) {
        return width;
    }

    @Override
    public float getSize(double width) {
        return (float) (width / 110D);
    }

    private int burnTime = 0;

    private int getBurnTimeRemainingScaled(int scale) {
        if (burnTime == 0) {
            burnTime = 2000;
        } else burnTime--;

        return burnTime * scale / 2000;
    }

    protected void drawBackground() {
        Minecraft.getInstance().getTextureManager().bindTexture(LOCATION);
        EnchiridionAPI.draw.drawTexturedRectangle(55D, 38D, 1, 63, 20, 14, 1.75F);
        int i1 = getBurnTimeRemainingScaled(13);
        EnchiridionAPI.draw.drawTexturedReversedRectangle(44D, 56D, 0, 85, 14, 14, 1.75F);
        EnchiridionAPI.draw.drawTexturedReversedRectangle(44D, 46D + 12D, 14, 98 - i1, 14, i1 + 1, 1.75F);
    }
}