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

import com.mojang.blaze3d.systems.RenderSystem;
import javax.annotation.Nullable;
import net.minecraft.network.chat.Component;

public class SystemToast implements Toast {
    private final SystemToastIds id;
    private String title;
    private String message;
    private long lastChanged;
    private boolean changed;
    
    public SystemToast(final SystemToastIds a, final Component lf2, @Nullable final Component lf3) {
        this.id = a;
        this.title = lf2.getString();
        this.message = ((lf3 == null) ? null : lf3.getString());
    }
    
    @Override
    public Visibility render(final ToastComponent deb, final long long2) {
        if (this.changed) {
            this.lastChanged = long2;
            this.changed = false;
        }
        deb.getMinecraft().getTextureManager().bind(SystemToast.TEXTURE);
        RenderSystem.color3f(1.0f, 1.0f, 1.0f);
        deb.blit(0, 0, 0, 64, 160, 32);
        if (this.message == null) {
            deb.getMinecraft().font.draw(this.title, 18.0f, 12.0f, -256);
        }
        else {
            deb.getMinecraft().font.draw(this.title, 18.0f, 7.0f, -256);
            deb.getMinecraft().font.draw(this.message, 18.0f, 18.0f, -1);
        }
        return (long2 - this.lastChanged < 5000L) ? Visibility.SHOW : Visibility.HIDE;
    }
    
    public void reset(final Component lf1, @Nullable final Component lf2) {
        this.title = lf1.getString();
        this.message = ((lf2 == null) ? null : lf2.getString());
        this.changed = true;
    }
    
    @Override
    public SystemToastIds getToken() {
        return this.id;
    }
    
    public static void addOrUpdate(final ToastComponent deb, final SystemToastIds a, final Component lf3, @Nullable final Component lf4) {
        final SystemToast ddz5 = deb.<SystemToast>getToast(SystemToast.class, a);
        if (ddz5 == null) {
            deb.addToast(new SystemToast(a, lf3, lf4));
        }
        else {
            ddz5.reset(lf3, lf4);
        }
    }
    
    public enum SystemToastIds {
        TUTORIAL_HINT, 
        NARRATOR_TOGGLE, 
        WORLD_BACKUP, 
        PACK_LOAD_FAILURE;
    }
}
