package speiger.src.coreengine.rendering.guiOld.components.window.misc;

import speiger.src.coreengine.math.color.ColorUtils;
import speiger.src.coreengine.rendering.guiOld.components.ButtonComponent;
import speiger.src.coreengine.rendering.guiOld.components.TextComponent;
import speiger.src.coreengine.rendering.guiOld.components.WindowComponent;
import speiger.src.coreengine.rendering.guiOld.helper.constrains.Constrains;
import speiger.src.coreengine.rendering.guiOld.helper.constrains.ParentConstrain;
import speiger.src.coreengine.rendering.guiOld.helper.constrains.PixelConstrain;
import speiger.src.coreengine.rendering.guiOld.helper.constrains.TextConstrain;

public class MessageComponent extends WindowComponent
{
	TextComponent message = new TextComponent().limitHeight(false).setTextScale(0.5F);
	ButtonComponent resultButton = new ButtonComponent("", ColorUtils.GRAY);
	
	public MessageComponent(float width, String windowTitle, String confirmButton, String message)
	{
		this(0F, 0F, width, windowTitle, confirmButton, message);
	}
	
	public MessageComponent(float x, float y, float width, String windowTitle, String confirmButton, String message)
	{
		super(x, y, width, 25F, FIXED_SIZE_POPUP, windowTitle);
		resultButton.getText().setText(confirmButton);
		this.message.setText(message);
	}
	
	public static MessageComponent createInfo(String message)
	{
		return new MessageComponent(150, "Info", "Ok", message);
	}
	
	public static MessageComponent createInfo(float width, String message)
	{
		return new MessageComponent(width, "Info", "Ok", message);
	}
	
	public static MessageComponent createWarn(String message)
	{
		return new MessageComponent(150, "Warn", "Ok", message);
	}
	
	public static MessageComponent createWarn(float width, String message)
	{
		return new MessageComponent(width, "Warn", "Ok", message);
	}
	
	public static MessageComponent createError(String message)
	{
		return new MessageComponent(150, "Error!", "Ok", message);
	}
	
	public static MessageComponent createError(float width, String message)
	{
		return new MessageComponent(width, "Error!", "Ok", message);
	}
	
	@Override
	public void init()
	{
		super.init();
		resultButton.getText().setTextScale(0.5F);
		addChild(resultButton.onChange(minimizedListener).onAction(closeListener), new Constrains(new ParentConstrain(), new ParentConstrain(10F).invert(), new ParentConstrain(), new PixelConstrain(10F)));
		addChild(message, new Constrains(new PixelConstrain(10F), new PixelConstrain(11F), new ParentConstrain(10F), TextConstrain.height(message)));
		getBox().setHeight(25F + message.getMetadata().getMaxHeight());
	}
	
	@Override
	public boolean isPopup()
	{
		return true;
	}
}
