package net.minecraft.realms;

import java.util.Iterator;
import net.minecraft.client.gui.Font;
import com.mojang.blaze3d.vertex.PoseStack;
import net.minecraft.client.gui.components.Button;
import net.minecraft.network.chat.CommonComponents;
import net.minecraft.client.Minecraft;
import net.minecraft.client.resources.language.I18n;
import net.minecraft.client.gui.screens.Screen;
import javax.annotation.Nullable;
import net.minecraft.network.chat.FormattedText;
import java.util.List;
import net.minecraft.network.chat.Component;

public class DisconnectedRealmsScreen extends RealmsScreen {
    private final String title;
    private final Component reason;
    @Nullable
    private List<FormattedText> lines;
    private final Screen parent;
    private int textHeight;
    
    public DisconnectedRealmsScreen(final Screen dqs, final String string, final Component mr) {
        this.parent = dqs;
        this.title = I18n.get(string);
        this.reason = mr;
    }
    
    public void init() {
        final Minecraft dlx2 = Minecraft.getInstance();
        dlx2.setConnectedToRealms(false);
        dlx2.getClientPackSource().clearServerPack();
        NarrationHelper.now(this.title + ": " + this.reason.getString());
        this.lines = this.font.split(this.reason, this.width - 50);
        final int size = this.lines.size();
        this.font.getClass();
        this.textHeight = size * 9;
        final int integer1 = this.width / 2 - 100;
        final int n = this.height / 2 + this.textHeight / 2;
        this.font.getClass();
        this.<Button>addButton(new Button(integer1, n + 9, 200, 20, CommonComponents.GUI_BACK, dni -> dlx2.setScreen(this.parent)));
    }
    
    @Override
    public boolean keyPressed(final int integer1, final int integer2, final int integer3) {
        if (integer1 == 256) {
            Minecraft.getInstance().setScreen(this.parent);
            return true;
        }
        return super.keyPressed(integer1, integer2, integer3);
    }
    
    @Override
    public void render(final PoseStack dhl, final int integer2, final int integer3, final float float4) {
        this.renderBackground(dhl);
        final Font font = this.font;
        final String title = this.title;
        final int integer5 = this.width / 2;
        final int n = this.height / 2 - this.textHeight / 2;
        this.font.getClass();
        this.drawCenteredString(dhl, font, title, integer5, n - 9 * 2, 11184810);
        int integer4 = this.height / 2 - this.textHeight / 2;
        if (this.lines != null) {
            for (final FormattedText mu8 : this.lines) {
                this.drawCenteredString(dhl, this.font, mu8, this.width / 2, integer4, 16777215);
                final int n2 = integer4;
                this.font.getClass();
                integer4 = n2 + 9;
            }
        }
        super.render(dhl, integer2, integer3, float4);
    }
}
