package net.minecraft.client.gui.components.toasts;

import net.minecraft.world.item.ItemStack;
import net.minecraft.client.resources.language.I18n;
import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.vertex.PoseStack;
import com.google.common.collect.Lists;
import net.minecraft.world.item.crafting.Recipe;
import java.util.List;

public class RecipeToast implements Toast {
    private final List<Recipe<?>> recipes;
    private long lastChanged;
    private boolean changed;
    
    public RecipeToast(final Recipe<?> bmu) {
        (this.recipes = Lists.newArrayList()).add(bmu);
    }
    
    @Override
    public Visibility render(final PoseStack dhl, final ToastComponent doo, final long long3) {
        if (this.changed) {
            this.lastChanged = long3;
            this.changed = false;
        }
        if (this.recipes.isEmpty()) {
            return Visibility.HIDE;
        }
        doo.getMinecraft().getTextureManager().bind(RecipeToast.TEXTURE);
        RenderSystem.color3f(1.0f, 1.0f, 1.0f);
        doo.blit(dhl, 0, 0, 0, 32, this.width(), this.height());
        doo.getMinecraft().font.draw(dhl, I18n.get("recipe.toast.title"), 30.0f, 7.0f, -11534256);
        doo.getMinecraft().font.draw(dhl, I18n.get("recipe.toast.description"), 30.0f, 18.0f, -16777216);
        final Recipe<?> bmu6 = this.recipes.get((int)(long3 / Math.max(1L, 5000L / this.recipes.size()) % this.recipes.size()));
        final ItemStack bki7 = bmu6.getToastSymbol();
        RenderSystem.pushMatrix();
        RenderSystem.scalef(0.6f, 0.6f, 1.0f);
        doo.getMinecraft().getItemRenderer().renderAndDecorateFakeItem(bki7, 3, 3);
        RenderSystem.popMatrix();
        doo.getMinecraft().getItemRenderer().renderAndDecorateFakeItem(bmu6.getResultItem(), 8, 8);
        return (long3 - this.lastChanged >= 5000L) ? Visibility.HIDE : Visibility.SHOW;
    }
    
    public void addItem(final Recipe<?> bmu) {
        if (this.recipes.add(bmu)) {
            this.changed = true;
        }
    }
    
    public static void addOrUpdate(final ToastComponent doo, final Recipe<?> bmu) {
        final RecipeToast dol3 = doo.<RecipeToast>getToast(RecipeToast.class, RecipeToast.NO_TOKEN);
        if (dol3 == null) {
            doo.addToast(new RecipeToast(bmu));
        }
        else {
            dol3.addItem(bmu);
        }
    }
}
