
package net.mcreator.sebmod.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.TextComponent;
import net.minecraft.network.chat.Component;
import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen;
import net.minecraft.client.gui.components.EditBox;
import net.minecraft.client.gui.components.Checkbox;
import net.minecraft.client.Minecraft;

import net.mcreator.sebmod.world.inventory.SebPCMenu;

import java.util.HashMap;

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

public class SebPCScreen extends AbstractContainerScreen<SebPCMenu> {
	private final static HashMap<String, Object> guistate = SebPCMenu.guistate;
	private final Level world;
	private final int x, y, z;
	private final Player entity;
	EditBox MenuText;
	Checkbox AmogusQ;

	public SebPCScreen(SebPCMenu 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 = 403;
		this.imageHeight = 211;
	}

	@Override
	public boolean isPauseScreen() {
		return true;
	}

	private static final ResourceLocation texture = new ResourceLocation("seb_mod:textures/seb_menu.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);
		MenuText.render(ms, mouseX, mouseY, partialTicks);
	}

	@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.setShaderTexture(0, new ResourceLocation("seb_mod:textures/seb-inc-logo.png"));
		this.blit(ms, this.leftPos + -40, this.topPos + -12, 0, 0, 114, 106, 114, 106);

		RenderSystem.setShaderTexture(0, new ResourceLocation("seb_mod:textures/amogusformenu.png"));
		this.blit(ms, this.leftPos + 240, this.topPos + 58, 0, 0, 16, 16, 16, 16);

		RenderSystem.disableBlend();
	}

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

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

	@Override
	protected void renderLabels(PoseStack poseStack, int mouseX, int mouseY) {
		this.font.draw(poseStack, "SebMod Menu", 5, 5, -12829636);
	}

	@Override
	public void onClose() {
		super.onClose();
		Minecraft.getInstance().keyboardHandler.setSendRepeatsToGui(false);
	}

	@Override
	public void init() {
		super.init();
		this.minecraft.keyboardHandler.setSendRepeatsToGui(true);
		MenuText = new EditBox(this.font, this.leftPos + 148, this.topPos + 11, 120, 20, new TextComponent("Type Random Stuff Here:")) {
			{
				setSuggestion("Type Random Stuff Here:");
			}

			@Override
			public void insertText(String text) {
				super.insertText(text);
				if (getValue().isEmpty())
					setSuggestion("Type Random Stuff Here:");
				else
					setSuggestion(null);
			}

			@Override
			public void moveCursorTo(int pos) {
				super.moveCursorTo(pos);
				if (getValue().isEmpty())
					setSuggestion("Type Random Stuff Here:");
				else
					setSuggestion(null);
			}
		};
		guistate.put("text:MenuText", MenuText);
		MenuText.setMaxLength(32767);
		this.addWidget(this.MenuText);
		AmogusQ = new Checkbox(this.leftPos + 175, this.topPos + 56, 150, 20, new TextComponent("Amogus?"), false);
		guistate.put("checkbox:AmogusQ", AmogusQ);
		this.addRenderableWidget(AmogusQ);
	}
}
