package net.mcreator.watermelon_play_simulator.client.gui;

import net.minecraft.world.level.Level;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.network.chat.Component;
import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen;
import net.minecraft.client.gui.components.Button;

import net.mcreator.watermelon_play_simulator.world.inventory.DgchooselevelMenu;
import net.mcreator.watermelon_play_simulator.procedures.Unlockdg14Procedure;
import net.mcreator.watermelon_play_simulator.procedures.Unlockdg13Procedure;
import net.mcreator.watermelon_play_simulator.procedures.Unlockdg12Procedure;
import net.mcreator.watermelon_play_simulator.network.DgchooselevelButtonMessage;
import net.mcreator.watermelon_play_simulator.WatermelonPlaySimulator2Mod;

import java.util.HashMap;

import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.blaze3d.systems.RenderSystem;

public class DgchooselevelScreen extends AbstractContainerScreen<DgchooselevelMenu> {
	private final static HashMap<String, Object> guistate = DgchooselevelMenu.guistate;
	private final Level world;
	private final int x, y, z;
	private final Player entity;
	Button button_dg11;
	Button button_dg12;
	Button button_dg13;
	Button button_dg14;

	public DgchooselevelScreen(DgchooselevelMenu container, Inventory inventory, Component text) {
		super(container, inventory, text);
		this.world = container.world;
		this.x = container.x;
		this.y = container.y;
		this.z = container.z;
		this.entity = container.entity;
		this.imageWidth = 320;
		this.imageHeight = 166;
	}

	private static final ResourceLocation texture = new ResourceLocation("watermelon_play_simulator_2:textures/screens/dgchooselevel.png");

	@Override
	public void render(PoseStack ms, int mouseX, int mouseY, float partialTicks) {
		this.renderBackground(ms);
		super.render(ms, mouseX, mouseY, partialTicks);
		this.renderTooltip(ms, mouseX, mouseY);
	}

	@Override
	protected void renderBg(PoseStack ms, float partialTicks, int gx, int gy) {
		RenderSystem.setShaderColor(1, 1, 1, 1);
		RenderSystem.enableBlend();
		RenderSystem.defaultBlendFunc();
		RenderSystem.setShaderTexture(0, texture);
		this.blit(ms, this.leftPos, this.topPos, 0, 0, this.imageWidth, this.imageHeight, this.imageWidth, this.imageHeight);
		RenderSystem.disableBlend();
	}

	@Override
	public boolean keyPressed(int key, int b, int c) {
		if (key == 256) {
			this.minecraft.player.closeContainer();
			return true;
		}
		return super.keyPressed(key, b, c);
	}

	@Override
	public void containerTick() {
		super.containerTick();
	}

	@Override
	protected void renderLabels(PoseStack poseStack, int mouseX, int mouseY) {
	}

	@Override
	public void onClose() {
		super.onClose();
	}

	@Override
	public void init() {
		super.init();
		button_dg11 = Button.builder(Component.translatable("gui.watermelon_play_simulator_2.dgchooselevel.button_dg11"), e -> {
			if (true) {
				WatermelonPlaySimulator2Mod.PACKET_HANDLER.sendToServer(new DgchooselevelButtonMessage(0, x, y, z));
				DgchooselevelButtonMessage.handleButtonAction(entity, 0, x, y, z);
			}
		}).bounds(this.leftPos + 6, this.topPos + 7, 51, 20).build();
		guistate.put("button:button_dg11", button_dg11);
		this.addRenderableWidget(button_dg11);
		button_dg12 = Button.builder(Component.translatable("gui.watermelon_play_simulator_2.dgchooselevel.button_dg12"), e -> {
			if (Unlockdg12Procedure.execute(entity)) {
				WatermelonPlaySimulator2Mod.PACKET_HANDLER.sendToServer(new DgchooselevelButtonMessage(1, x, y, z));
				DgchooselevelButtonMessage.handleButtonAction(entity, 1, x, y, z);
			}
		}).bounds(this.leftPos + 69, this.topPos + 7, 51, 20).build(builder -> new Button(builder) {
			@Override
			public void render(PoseStack ms, int gx, int gy, float ticks) {
				if (Unlockdg12Procedure.execute(entity))
					super.render(ms, gx, gy, ticks);
			}
		});
		guistate.put("button:button_dg12", button_dg12);
		this.addRenderableWidget(button_dg12);
		button_dg13 = Button.builder(Component.translatable("gui.watermelon_play_simulator_2.dgchooselevel.button_dg13"), e -> {
			if (Unlockdg13Procedure.execute(entity)) {
				WatermelonPlaySimulator2Mod.PACKET_HANDLER.sendToServer(new DgchooselevelButtonMessage(2, x, y, z));
				DgchooselevelButtonMessage.handleButtonAction(entity, 2, x, y, z);
			}
		}).bounds(this.leftPos + 132, this.topPos + 7, 51, 20).build(builder -> new Button(builder) {
			@Override
			public void render(PoseStack ms, int gx, int gy, float ticks) {
				if (Unlockdg13Procedure.execute(entity))
					super.render(ms, gx, gy, ticks);
			}
		});
		guistate.put("button:button_dg13", button_dg13);
		this.addRenderableWidget(button_dg13);
		button_dg14 = Button.builder(Component.translatable("gui.watermelon_play_simulator_2.dgchooselevel.button_dg14"), e -> {
			if (Unlockdg14Procedure.execute(entity)) {
				WatermelonPlaySimulator2Mod.PACKET_HANDLER.sendToServer(new DgchooselevelButtonMessage(3, x, y, z));
				DgchooselevelButtonMessage.handleButtonAction(entity, 3, x, y, z);
			}
		}).bounds(this.leftPos + 195, this.topPos + 7, 51, 20).build(builder -> new Button(builder) {
			@Override
			public void render(PoseStack ms, int gx, int gy, float ticks) {
				if (Unlockdg14Procedure.execute(entity))
					super.render(ms, gx, gy, ticks);
			}
		});
		guistate.put("button:button_dg14", button_dg14);
		this.addRenderableWidget(button_dg14);
	}
}
