package net.minecraft.client.gui.screens;

import net.minecraft.client.gui.components.AbstractWidget;
import java.util.Iterator;
import com.mojang.blaze3d.vertex.PoseStack;
import java.util.Collection;
import net.minecraft.client.gui.components.Button;
import com.google.common.collect.Lists;
import net.minecraft.network.chat.CommonComponents;
import it.unimi.dsi.fastutil.booleans.BooleanConsumer;
import net.minecraft.network.chat.FormattedText;
import java.util.List;
import net.minecraft.network.chat.Component;

public class ConfirmScreen extends Screen {
    private final Component title2;
    private final List<FormattedText> lines;
    protected Component yesButton;
    protected Component noButton;
    private int delayTicker;
    protected final BooleanConsumer callback;
    
    public ConfirmScreen(final BooleanConsumer booleanConsumer, final Component mr2, final Component mr3) {
        this(booleanConsumer, mr2, mr3, CommonComponents.GUI_YES, CommonComponents.GUI_NO);
    }
    
    public ConfirmScreen(final BooleanConsumer booleanConsumer, final Component mr2, final Component mr3, final Component mr4, final Component mr5) {
        super(mr2);
        this.lines = Lists.newArrayList();
        this.callback = booleanConsumer;
        this.title2 = mr3;
        this.yesButton = mr4;
        this.noButton = mr5;
    }
    
    @Override
    public String getNarrationMessage() {
        return super.getNarrationMessage() + ". " + this.title2.getString();
    }
    
    @Override
    protected void init() {
        super.init();
        this.<Button>addButton(new Button(this.width / 2 - 155, this.height / 6 + 96, 150, 20, this.yesButton, dni -> this.callback.accept(true)));
        this.<Button>addButton(new Button(this.width / 2 - 155 + 160, this.height / 6 + 96, 150, 20, this.noButton, dni -> this.callback.accept(false)));
        this.lines.clear();
        this.lines.addAll(this.font.split(this.title2, this.width - 50));
    }
    
    @Override
    public void render(final PoseStack dhl, final int integer2, final int integer3, final float float4) {
        this.renderBackground(dhl);
        this.drawCenteredString(dhl, this.font, this.title, this.width / 2, 70, 16777215);
        int integer4 = 90;
        for (final FormattedText mu8 : this.lines) {
            this.drawCenteredString(dhl, this.font, mu8, this.width / 2, integer4, 16777215);
            final int n = integer4;
            this.font.getClass();
            integer4 = n + 9;
        }
        super.render(dhl, integer2, integer3, float4);
    }
    
    public void setDelay(final int integer) {
        this.delayTicker = integer;
        for (final AbstractWidget dng4 : this.buttons) {
            dng4.active = false;
        }
    }
    
    @Override
    public void tick() {
        super.tick();
        final int delayTicker = this.delayTicker - 1;
        this.delayTicker = delayTicker;
        if (delayTicker == 0) {
            for (final AbstractWidget dng3 : this.buttons) {
                dng3.active = true;
            }
        }
    }
    
    @Override
    public boolean shouldCloseOnEsc() {
        return false;
    }
    
    @Override
    public boolean keyPressed(final int integer1, final int integer2, final int integer3) {
        if (integer1 == 256) {
            this.callback.accept(false);
            return true;
        }
        return super.keyPressed(integer1, integer2, integer3);
    }
}
