package speiger.src.coreengine.rendering.guiOld;

import java.util.Map;
import java.util.UUID;

import speiger.src.collections.objects.maps.impl.hash.Object2ObjectLinkedOpenHashMap;

public class Tooltips
{
	Map<UUID, GuiComponent> components = new Object2ObjectLinkedOpenHashMap<>();
	
	public <T extends GuiComponent> T addComponent(T comp)
	{
		return addComponent(UUID.randomUUID(), comp);
	}
	
	public <T extends GuiComponent> T addComponent(UUID id, T comp)
	{
		if(comp.tooltipId != null) throw new IllegalStateException("A Tooltip can not be added to another container");
		components.put(id, comp);
		comp.tooltipId = id;
		return comp;
	}
	
	public boolean contains(UUID id)
	{
		return components.containsKey(id);
	}
	
	public GuiComponent removeTooltip(UUID id)
	{
		GuiComponent comp = components.remove(id);
		if(comp != null) comp.tooltipId = null;
		return comp;
	}
	
	public void merge(Map<UUID, GuiComponent> collector)
	{
		collector.putAll(components);
	}
	
	public void clear()
	{
		for(GuiComponent comp : components.values())
		{
			comp.tooltipId = null;
		}
	}
}
