package net.mcreator.gts.client.gui;

import net.neoforged.neoforge.network.PacketDistributor;

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.minecraft.client.gui.GuiGraphics;

import net.mcreator.gts.world.inventory.GtsCommonGuiPage2Menu;
import net.mcreator.gts.procedures.CheckDisableTamedMobAggroProcedure;
import net.mcreator.gts.procedures.CheckDisableTamedFriendlyFireProcedure;
import net.mcreator.gts.procedures.CheckDisableTamedBreachProcedure;
import net.mcreator.gts.procedures.CheckDisableEatAttackDependOnHealthProcedure;
import net.mcreator.gts.procedures.CheckChancedBasedEscapeProcedure;
import net.mcreator.gts.procedures.CheckBiomeSpawnProcedure;
import net.mcreator.gts.network.GtsCommonGuiPage2ButtonMessage;

import java.util.HashMap;

import com.mojang.blaze3d.systems.RenderSystem;

public class GtsCommonGuiPage2Screen extends AbstractContainerScreen<GtsCommonGuiPage2Menu> {
	private final static HashMap<String, Object> guistate = GtsCommonGuiPage2Menu.guistate;
	private final Level world;
	private final int x, y, z;
	private final Player entity;
	Button button_previous_page;
	Button button_tamed_giantess_friendly_fire;
	Button button_tamed_giantess_seek_out_monsters;
	Button button_tamed_giantess_breach_attack;
	Button button_eat_attacks_depend_on_health;
	Button button_chance_based_grab_escape;
	Button button_disable_biome_dependent_spawn;

	public GtsCommonGuiPage2Screen(GtsCommonGuiPage2Menu 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 = 400;
		this.imageHeight = 200;
	}

	private static final ResourceLocation texture = ResourceLocation.parse("gts:textures/screens/gts_common_gui_page_2.png");

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

	@Override
	protected void renderBg(GuiGraphics guiGraphics, float partialTicks, int gx, int gy) {
		RenderSystem.setShaderColor(1, 1, 1, 1);
		RenderSystem.enableBlend();
		RenderSystem.defaultBlendFunc();
		guiGraphics.blit(texture, 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
	protected void renderLabels(GuiGraphics guiGraphics, int mouseX, int mouseY) {
		guiGraphics.drawString(this.font, Component.translatable("gui.gts.gts_common_gui_page_2.label_giantess_config_main_menu"), 9, 11, -12829636, false);
		guiGraphics.drawString(this.font, Component.translatable("gui.gts.gts_common_gui_page_2.label_page_2"), 360, 10, -12829636, false);
		guiGraphics.drawString(this.font, Component.translatable("gui.gts.gts_common_gui_page_2.label_tamed_giantess_config"), 7, 112, -12829636, false);
		guiGraphics.drawString(this.font,

				CheckDisableTamedFriendlyFireProcedure.execute(world), 181, 130, -12829636, false);
		guiGraphics.drawString(this.font,

				CheckDisableTamedMobAggroProcedure.execute(world), 202, 153, -12829636, false);
		guiGraphics.drawString(this.font,

				CheckDisableTamedBreachProcedure.execute(world), 180, 177, -12829636, false);
		guiGraphics.drawString(this.font, Component.translatable("gui.gts.gts_common_gui_page_2.label_general_giantess_behavior_cont"), 8, 34, -12829636, false);
		guiGraphics.drawString(this.font,

				CheckDisableEatAttackDependOnHealthProcedure.execute(world), 181, 49, -12829636, false);
		guiGraphics.drawString(this.font,

				CheckChancedBasedEscapeProcedure.execute(world), 160, 72, -12829636, false);
		guiGraphics.drawString(this.font,

				CheckBiomeSpawnProcedure.execute(world), 186, 96, -12829636, false);
	}

	@Override
	public void init() {
		super.init();
		button_previous_page = Button.builder(Component.translatable("gui.gts.gts_common_gui_page_2.button_previous_page"), e -> {
			if (true) {
				PacketDistributor.sendToServer(new GtsCommonGuiPage2ButtonMessage(0, x, y, z));
				GtsCommonGuiPage2ButtonMessage.handleButtonAction(entity, 0, x, y, z);
			}
		}).bounds(this.leftPos + 261, this.topPos + 5, 93, 20).build();
		guistate.put("button:button_previous_page", button_previous_page);
		this.addRenderableWidget(button_previous_page);
		button_tamed_giantess_friendly_fire = Button.builder(Component.translatable("gui.gts.gts_common_gui_page_2.button_tamed_giantess_friendly_fire"), e -> {
			if (true) {
				PacketDistributor.sendToServer(new GtsCommonGuiPage2ButtonMessage(1, x, y, z));
				GtsCommonGuiPage2ButtonMessage.handleButtonAction(entity, 1, x, y, z);
			}
		}).bounds(this.leftPos + 7, this.topPos + 125, 171, 20).build();
		guistate.put("button:button_tamed_giantess_friendly_fire", button_tamed_giantess_friendly_fire);
		this.addRenderableWidget(button_tamed_giantess_friendly_fire);
		button_tamed_giantess_seek_out_monsters = Button.builder(Component.translatable("gui.gts.gts_common_gui_page_2.button_tamed_giantess_seek_out_monsters"), e -> {
			if (true) {
				PacketDistributor.sendToServer(new GtsCommonGuiPage2ButtonMessage(2, x, y, z));
				GtsCommonGuiPage2ButtonMessage.handleButtonAction(entity, 2, x, y, z);
			}
		}).bounds(this.leftPos + 7, this.topPos + 148, 192, 20).build();
		guistate.put("button:button_tamed_giantess_seek_out_monsters", button_tamed_giantess_seek_out_monsters);
		this.addRenderableWidget(button_tamed_giantess_seek_out_monsters);
		button_tamed_giantess_breach_attack = Button.builder(Component.translatable("gui.gts.gts_common_gui_page_2.button_tamed_giantess_breach_attack"), e -> {
			if (true) {
				PacketDistributor.sendToServer(new GtsCommonGuiPage2ButtonMessage(3, x, y, z));
				GtsCommonGuiPage2ButtonMessage.handleButtonAction(entity, 3, x, y, z);
			}
		}).bounds(this.leftPos + 7, this.topPos + 171, 171, 20).build();
		guistate.put("button:button_tamed_giantess_breach_attack", button_tamed_giantess_breach_attack);
		this.addRenderableWidget(button_tamed_giantess_breach_attack);
		button_eat_attacks_depend_on_health = Button.builder(Component.translatable("gui.gts.gts_common_gui_page_2.button_eat_attacks_depend_on_health"), e -> {
			if (true) {
				PacketDistributor.sendToServer(new GtsCommonGuiPage2ButtonMessage(4, x, y, z));
				GtsCommonGuiPage2ButtonMessage.handleButtonAction(entity, 4, x, y, z);
			}
		}).bounds(this.leftPos + 8, this.topPos + 44, 171, 20).build();
		guistate.put("button:button_eat_attacks_depend_on_health", button_eat_attacks_depend_on_health);
		this.addRenderableWidget(button_eat_attacks_depend_on_health);
		button_chance_based_grab_escape = Button.builder(Component.translatable("gui.gts.gts_common_gui_page_2.button_chance_based_grab_escape"), e -> {
			if (true) {
				PacketDistributor.sendToServer(new GtsCommonGuiPage2ButtonMessage(5, x, y, z));
				GtsCommonGuiPage2ButtonMessage.handleButtonAction(entity, 5, x, y, z);
			}
		}).bounds(this.leftPos + 8, this.topPos + 67, 150, 20).build();
		guistate.put("button:button_chance_based_grab_escape", button_chance_based_grab_escape);
		this.addRenderableWidget(button_chance_based_grab_escape);
		button_disable_biome_dependent_spawn = Button.builder(Component.translatable("gui.gts.gts_common_gui_page_2.button_disable_biome_dependent_spawn"), e -> {
			if (true) {
				PacketDistributor.sendToServer(new GtsCommonGuiPage2ButtonMessage(6, x, y, z));
				GtsCommonGuiPage2ButtonMessage.handleButtonAction(entity, 6, x, y, z);
			}
		}).bounds(this.leftPos + 8, this.topPos + 90, 176, 20).build();
		guistate.put("button:button_disable_biome_dependent_spawn", button_disable_biome_dependent_spawn);
		this.addRenderableWidget(button_disable_biome_dependent_spawn);
	}
}
