package info.u_team.u_team_core.gui.elements;

import java.util.ArrayList;
import java.util.List;

import com.mojang.blaze3d.vertex.PoseStack;

import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.components.AbstractSelectionList;
import net.minecraft.client.gui.components.AbstractWidget;
import net.minecraft.client.gui.components.ObjectSelectionList;

public abstract class ScrollableListEntry<T extends ScrollableListEntry<T>> extends ObjectSelectionList.Entry<T> {
	
	protected final Minecraft minecraft;
	
	private final List<AbstractWidget> widgets;
	
	public ScrollableListEntry() {
		minecraft = Minecraft.getInstance();
		widgets = new ArrayList<>();
	}
	
	// TODO rename to match screen
	protected <B extends AbstractWidget> B addButton(B button) {
		widgets.add(button);
		return button;
	}
	
	@Override
	public boolean mouseClicked(double mouseX, double mouseY, int button) {
		widgets.forEach(widget -> widget.mouseClicked(mouseX, mouseY, button));
		return true;
	}
	
	@Override
	public boolean mouseReleased(double mouseX, double mouseY, int button) {
		for (final var widget : widgets) {
			if (widget.mouseReleased(mouseX, mouseY, button)) {
				return true;
			}
		}
		return false;
	}
	
	@Override
	public boolean mouseDragged(double mouseX, double mouseY, int button, double dragX, double dragY) {
		for (final var widget : widgets) {
			if (widget.mouseDragged(mouseX, mouseY, button, dragX, dragY)) {
				return true;
			}
		}
		return false;
	}
	
	@Override
	public abstract void render(PoseStack poseStack, int slotIndex, int entryY, int entryX, int entryWidth, int entryHeight, int mouseX, int mouseY, boolean hovered, float partialTicks);
	
	@SuppressWarnings("deprecation")
	protected AbstractSelectionList<T> getList() {
		return list;
	}
}

@@ -285,29 +285,34 @@
 ponents.
-AbstractWidge
+ObjectSelectionLis
 t;%0Aimpor
@@ -349,35 +349,39 @@
 ponents.
-ObjectSelectionList
+events.GuiEventListener
 ;%0A%0Apubli
@@ -556,31 +556,34 @@
 ist%3C
-AbstractWidget%3E widgets
+GuiEventListener%3E children
 ;%0A%09%0A
@@ -655,23 +655,24 @@
 ce();%0A%09%09
-widgets
+children
  = new A
@@ -695,121 +695,98 @@
 %0A%09%0A%09
-// TODO rename to match screen%0A%09protected %3CB extends AbstractWidget%3E B addButton(B button) %7B%0A%09%09widgets.add(button
+protected %3CB extends GuiEventListener%3E B addChildren(B listener) %7B%0A%09%09children.add(listener
 );%0A%09
@@ -793,22 +793,24 @@
 %09return 
-button
+listener
 ;%0A%09%7D%0A%09%0A%09
@@ -894,23 +894,24 @@
 on) %7B%0A%09%09
-widgets
+children
 .forEach
@@ -915,24 +915,28 @@
 ach(
-widget -%3E widget
+listener -%3E listener
 .mou
@@ -1093,32 +1093,35 @@
 nal var 
-widget : widgets
+listener : children
 ) %7B%0A%09%09%09i
@@ -1119,30 +1119,32 @@
 n) %7B%0A%09%09%09if (
-widget
+listener
 .mouseReleas
@@ -1353,24 +1353,27 @@
 var 
-widget : widgets
+listener : children
 ) %7B%0A
@@ -1383,14 +1383,16 @@
 if (
-widget
+listener
 .mou
@@ -1558,13 +1558,9 @@
 int 
-slotI
+i
 ndex
@@ -1569,38 +1569,28 @@
 int 
-entryY, int entryX, int entryW
+top, int left, int w
 idth
@@ -1599,14 +1599,9 @@
 int 
-entryH
+h
 eigh

Rename method to match other gui types