package com.dairymoose.modernlife.blocks.gui;

import com.dairymoose.modernlife.core.ModernLifeNetwork;
import com.dairymoose.modernlife.network.play.client.ServerboundPrintSizePacket;
import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.vertex.PoseStack;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Font;
import net.minecraft.client.gui.components.Button;
import net.minecraft.client.gui.components.ImageButton;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.client.renderer.GameRenderer;
import net.minecraft.core.BlockPos;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.Style;
import net.minecraft.network.chat.TextColor;
import net.minecraft.network.chat.TextComponent;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.FormattedCharSequence;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

@OnlyIn(Dist.CLIENT)
/* loaded from: outputsrg.jar:com/dairymoose/modernlife/blocks/gui/PrinterScreen.class */
public class PrinterScreen extends Screen {
    private static final Logger LOGGER = LogManager.getLogger();
    private static final ResourceLocation PRINTER_GUI = new ResourceLocation("modernlife", "textures/gui/gui_printer.png");
    final int GUI_WIDTH = 132;
    final int GUI_HEIGHT = 175;
    BlockPos pos;
    private boolean widePrintMode;
    private static final String PRINT_SIZE = "Print Size";

    private static Component getComponentForTitle(String title) {
        return new TextComponent(title).m_6270_(Style.EMPTY.withColor(TextColor.fromRgb(4210752)));
    }

    public PrinterScreen(BlockPos pos) {
        super(getComponentForTitle(PRINT_SIZE));
        this.GUI_WIDTH = 132;
        this.GUI_HEIGHT = 175;
        this.widePrintMode = true;
        this.pos = pos;
    }

    protected void addSquareButton(int startX, int startY) {
        if (this.widePrintMode) {
            addRenderableWidget(new ImageButton(startX, startY + 96, 106, 20, 150, 160, 20, PRINTER_GUI, new Button.OnPress() { // from class: com.dairymoose.modernlife.blocks.gui.PrinterScreen.1
                final /* synthetic */ PrinterScreen val$thisPrinter;
                final /* synthetic */ int val$startX;
                final /* synthetic */ int val$startY;

                C00941(PrinterScreen this, int startX2, int startY2) {
                    this = this;
                    startX = startX2;
                    startY = startY2;
                }

                public void onPress(Button arg0) {
                    this.removeWidget(arg0);
                    this.widePrintMode = false;
                    this.addSquareButton(startX, startY);
                }
            }));
        } else {
            addRenderableWidget(new ImageButton(startX2, startY2 + 96, 106, 20, 150, 200, 20, PRINTER_GUI, new Button.OnPress() { // from class: com.dairymoose.modernlife.blocks.gui.PrinterScreen.2
                final /* synthetic */ PrinterScreen val$thisPrinter;
                final /* synthetic */ int val$startX;
                final /* synthetic */ int val$startY;

                C00952(PrinterScreen this, int startX2, int startY2) {
                    this = this;
                    startX = startX2;
                    startY = startY2;
                }

                public void onPress(Button arg0) {
                    this.removeWidget(arg0);
                    this.widePrintMode = true;
                    this.addSquareButton(startX, startY);
                }
            }));
        }
    }

    /* renamed from: com.dairymoose.modernlife.blocks.gui.PrinterScreen$1 */
    /* loaded from: outputsrg.jar:com/dairymoose/modernlife/blocks/gui/PrinterScreen$1.class */
    public class C00941 implements Button.OnPress {
        final /* synthetic */ PrinterScreen val$thisPrinter;
        final /* synthetic */ int val$startX;
        final /* synthetic */ int val$startY;

        C00941(PrinterScreen this, int startX2, int startY2) {
            this = this;
            startX = startX2;
            startY = startY2;
        }

        public void onPress(Button arg0) {
            this.removeWidget(arg0);
            this.widePrintMode = false;
            this.addSquareButton(startX, startY);
        }
    }

    /* renamed from: com.dairymoose.modernlife.blocks.gui.PrinterScreen$2 */
    /* loaded from: outputsrg.jar:com/dairymoose/modernlife/blocks/gui/PrinterScreen$2.class */
    public class C00952 implements Button.OnPress {
        final /* synthetic */ PrinterScreen val$thisPrinter;
        final /* synthetic */ int val$startX;
        final /* synthetic */ int val$startY;

        C00952(PrinterScreen this, int startX2, int startY2) {
            this = this;
            startX = startX2;
            startY = startY2;
        }

        public void onPress(Button arg0) {
            this.removeWidget(arg0);
            this.widePrintMode = true;
            this.addSquareButton(startX, startY);
        }
    }

    protected void init() {
        int startX = ((this.width - 132) / 2) + 13;
        int startY = ((this.height - 175) / 2) + 25;
        addRenderableWidget(new ImageButton(startX, startY + 0, 106, 20, 150, 0, 20, PRINTER_GUI, new Button.OnPress() { // from class: com.dairymoose.modernlife.blocks.gui.PrinterScreen.3
            final /* synthetic */ PrinterScreen val$thisPrinter;

            C00963(PrinterScreen this) {
                this = this;
            }

            public void onPress(Button arg0) {
                if (this.widePrintMode) {
                    ModernLifeNetwork.INSTANCE.sendToServer(new ServerboundPrintSizePacket(1, PrinterScreen.this.pos));
                } else {
                    ModernLifeNetwork.INSTANCE.sendToServer(new ServerboundPrintSizePacket(1, PrinterScreen.this.pos));
                }
                Minecraft.getInstance().setScreen((Screen) null);
            }
        }));
        addRenderableWidget(new ImageButton(startX, startY + 24, 106, 20, 150, 40, 20, PRINTER_GUI, new Button.OnPress() { // from class: com.dairymoose.modernlife.blocks.gui.PrinterScreen.4
            final /* synthetic */ PrinterScreen val$thisPrinter;

            C00974(PrinterScreen this) {
                this = this;
            }

            public void onPress(Button arg0) {
                if (this.widePrintMode) {
                    ModernLifeNetwork.INSTANCE.sendToServer(new ServerboundPrintSizePacket(2, PrinterScreen.this.pos));
                } else {
                    ModernLifeNetwork.INSTANCE.sendToServer(new ServerboundPrintSizePacket(5, PrinterScreen.this.pos));
                }
                Minecraft.getInstance().setScreen((Screen) null);
            }
        }));
        addRenderableWidget(new ImageButton(startX, startY + 48, 106, 20, 150, 80, 20, PRINTER_GUI, new Button.OnPress() { // from class: com.dairymoose.modernlife.blocks.gui.PrinterScreen.5
            final /* synthetic */ PrinterScreen val$thisPrinter;

            C00985(PrinterScreen this) {
                this = this;
            }

            public void onPress(Button arg0) {
                if (this.widePrintMode) {
                    ModernLifeNetwork.INSTANCE.sendToServer(new ServerboundPrintSizePacket(3, PrinterScreen.this.pos));
                } else {
                    ModernLifeNetwork.INSTANCE.sendToServer(new ServerboundPrintSizePacket(6, PrinterScreen.this.pos));
                }
                Minecraft.getInstance().setScreen((Screen) null);
            }
        }));
        addRenderableWidget(new ImageButton(startX, startY + 72, 106, 20, 150, 120, 20, PRINTER_GUI, new Button.OnPress() { // from class: com.dairymoose.modernlife.blocks.gui.PrinterScreen.6
            final /* synthetic */ PrinterScreen val$thisPrinter;

            C00996(PrinterScreen this) {
                this = this;
            }

            public void onPress(Button arg0) {
                if (this.widePrintMode) {
                    ModernLifeNetwork.INSTANCE.sendToServer(new ServerboundPrintSizePacket(4, PrinterScreen.this.pos));
                } else {
                    ModernLifeNetwork.INSTANCE.sendToServer(new ServerboundPrintSizePacket(7, PrinterScreen.this.pos));
                }
                Minecraft.getInstance().setScreen((Screen) null);
            }
        }));
        addSquareButton(startX, startY);
        addRenderableWidget(new ImageButton(startX, startY + 120, 106, 20, 44, 200, 20, PRINTER_GUI, new Button.OnPress() { // from class: com.dairymoose.modernlife.blocks.gui.PrinterScreen.7
            C01007() {
            }

            public void onPress(Button arg0) {
                Minecraft.getInstance().setScreen(new CustomPrintScreen(PrinterScreen.this.pos));
            }
        }));
    }

    /* renamed from: com.dairymoose.modernlife.blocks.gui.PrinterScreen$3 */
    /* loaded from: outputsrg.jar:com/dairymoose/modernlife/blocks/gui/PrinterScreen$3.class */
    class C00963 implements Button.OnPress {
        final /* synthetic */ PrinterScreen val$thisPrinter;

        C00963(PrinterScreen this) {
            this = this;
        }

        public void onPress(Button arg0) {
            if (this.widePrintMode) {
                ModernLifeNetwork.INSTANCE.sendToServer(new ServerboundPrintSizePacket(1, PrinterScreen.this.pos));
            } else {
                ModernLifeNetwork.INSTANCE.sendToServer(new ServerboundPrintSizePacket(1, PrinterScreen.this.pos));
            }
            Minecraft.getInstance().setScreen((Screen) null);
        }
    }

    /* renamed from: com.dairymoose.modernlife.blocks.gui.PrinterScreen$4 */
    /* loaded from: outputsrg.jar:com/dairymoose/modernlife/blocks/gui/PrinterScreen$4.class */
    class C00974 implements Button.OnPress {
        final /* synthetic */ PrinterScreen val$thisPrinter;

        C00974(PrinterScreen this) {
            this = this;
        }

        public void onPress(Button arg0) {
            if (this.widePrintMode) {
                ModernLifeNetwork.INSTANCE.sendToServer(new ServerboundPrintSizePacket(2, PrinterScreen.this.pos));
            } else {
                ModernLifeNetwork.INSTANCE.sendToServer(new ServerboundPrintSizePacket(5, PrinterScreen.this.pos));
            }
            Minecraft.getInstance().setScreen((Screen) null);
        }
    }

    /* renamed from: com.dairymoose.modernlife.blocks.gui.PrinterScreen$5 */
    /* loaded from: outputsrg.jar:com/dairymoose/modernlife/blocks/gui/PrinterScreen$5.class */
    class C00985 implements Button.OnPress {
        final /* synthetic */ PrinterScreen val$thisPrinter;

        C00985(PrinterScreen this) {
            this = this;
        }

        public void onPress(Button arg0) {
            if (this.widePrintMode) {
                ModernLifeNetwork.INSTANCE.sendToServer(new ServerboundPrintSizePacket(3, PrinterScreen.this.pos));
            } else {
                ModernLifeNetwork.INSTANCE.sendToServer(new ServerboundPrintSizePacket(6, PrinterScreen.this.pos));
            }
            Minecraft.getInstance().setScreen((Screen) null);
        }
    }

    /* renamed from: com.dairymoose.modernlife.blocks.gui.PrinterScreen$6 */
    /* loaded from: outputsrg.jar:com/dairymoose/modernlife/blocks/gui/PrinterScreen$6.class */
    class C00996 implements Button.OnPress {
        final /* synthetic */ PrinterScreen val$thisPrinter;

        C00996(PrinterScreen this) {
            this = this;
        }

        public void onPress(Button arg0) {
            if (this.widePrintMode) {
                ModernLifeNetwork.INSTANCE.sendToServer(new ServerboundPrintSizePacket(4, PrinterScreen.this.pos));
            } else {
                ModernLifeNetwork.INSTANCE.sendToServer(new ServerboundPrintSizePacket(7, PrinterScreen.this.pos));
            }
            Minecraft.getInstance().setScreen((Screen) null);
        }
    }

    /* renamed from: com.dairymoose.modernlife.blocks.gui.PrinterScreen$7 */
    /* loaded from: outputsrg.jar:com/dairymoose/modernlife/blocks/gui/PrinterScreen$7.class */
    class C01007 implements Button.OnPress {
        C01007() {
        }

        public void onPress(Button arg0) {
            Minecraft.getInstance().setScreen(new CustomPrintScreen(PrinterScreen.this.pos));
        }
    }

    public boolean isPauseScreen() {
        return false;
    }

    private void drawCenteredStringNoShadow(PoseStack p_238472_0_, Font p_238472_1_, Component p_238472_2_, int p_238472_3_, int p_238472_4_, int p_238472_5_) {
        FormattedCharSequence lvt_6_1_ = p_238472_2_.getVisualOrderText();
        p_238472_1_.draw(p_238472_0_, lvt_6_1_, p_238472_3_ - (p_238472_1_.width(lvt_6_1_) / 2), p_238472_4_, p_238472_5_);
    }

    public void render(PoseStack p_230430_1_, int p_230430_2_, int p_230430_3_, float p_230430_4_) {
        RenderSystem.setShader(GameRenderer::getPositionTexShader);
        RenderSystem.setShaderTexture(0, PRINTER_GUI);
        int lvt_5_1_ = (this.width - 132) / 2;
        int lvt_6_1_ = (this.height - 175) / 2;
        m_93228_(p_230430_1_, lvt_5_1_, lvt_6_1_, 0, 0, 132, 175);
        drawCenteredStringNoShadow(p_230430_1_, this.minecraft.font, this.title, lvt_5_1_ + 66, lvt_6_1_ + 5, 0);
        super.render(p_230430_1_, p_230430_2_, p_230430_3_, p_230430_4_);
    }
}
