package net.minecraft.client.gui.screens;

import java.util.Iterator;
import net.minecraft.client.gui.Font;
import com.mojang.blaze3d.vertex.PoseStack;
import com.google.common.collect.UnmodifiableIterator;
import net.minecraft.client.gui.components.Button;
import net.minecraft.client.Minecraft;
import net.minecraft.network.chat.Component;
import java.util.List;
import com.google.common.collect.ImmutableList;
import net.minecraft.network.chat.FormattedText;

public class PopupScreen extends Screen {
    private final FormattedText message;
    private final ImmutableList<ButtonOption> buttonOptions;
    private List<FormattedText> messageLines;
    private int contentTop;
    private int buttonWidth;
    
    protected PopupScreen(final Component mr, final List<FormattedText> list, final ImmutableList<ButtonOption> immutableList) {
        super(mr);
        this.message = FormattedText.composite(list);
        this.buttonOptions = immutableList;
    }
    
    @Override
    public String getNarrationMessage() {
        return super.getNarrationMessage() + ". " + this.message.getString();
    }
    
    @Override
    public void init(final Minecraft dlx, final int integer2, final int integer3) {
        super.init(dlx, integer2, integer3);
        for (final ButtonOption a6 : this.buttonOptions) {
            this.buttonWidth = Math.max(this.buttonWidth, 20 + this.font.width(a6.message) + 20);
        }
        final int integer4 = 5 + this.buttonWidth + 5;
        final int integer5 = integer4 * this.buttonOptions.size();
        this.messageLines = this.font.split(this.message, integer5);
        final int size = this.messageLines.size();
        this.font.getClass();
        final int integer6 = size * 9;
        this.contentTop = (int)(integer3 / 2.0 - integer6 / 2.0);
        final int n = this.contentTop + integer6;
        this.font.getClass();
        final int integer7 = n + 9 * 2;
        int integer8 = (int)(integer2 / 2.0 - integer5 / 2.0);
        for (final ButtonOption a7 : this.buttonOptions) {
            this.<Button>addButton(new Button(integer8, integer7, this.buttonWidth, 20, a7.message, a7.onPress));
            integer8 += integer4;
        }
    }
    
    @Override
    public void render(final PoseStack dhl, final int integer2, final int integer3, final float float4) {
        this.renderDirtBackground(0);
        final Font font = this.font;
        final Component title = this.title;
        final int integer5 = this.width / 2;
        final int contentTop = this.contentTop;
        this.font.getClass();
        this.drawCenteredString(dhl, font, title, integer5, contentTop - 9 * 2, -1);
        int integer4 = this.contentTop;
        for (final FormattedText mu8 : this.messageLines) {
            this.drawCenteredString(dhl, this.font, mu8, this.width / 2, integer4, -1);
            final int n = integer4;
            this.font.getClass();
            integer4 = n + 9;
        }
        super.render(dhl, integer2, integer3, float4);
    }
    
    @Override
    public boolean shouldCloseOnEsc() {
        return false;
    }
    
    public static final class ButtonOption {
        private final Component message;
        private final Button.OnPress onPress;
        
        public ButtonOption(final Component mr, final Button.OnPress a) {
            this.message = mr;
            this.onPress = a;
        }
    }
}
