package projectzombie.menu.gui;

import gl_engine.matrix.Matrix4;
import gl_engine.vec.Vec2d;
import gl_engine.vec.Vec3d;
import projectzombie.init.Models;
import projectzombie.model.ModelGui;
import projectzombie.text.Text;

public class GUISavesCard implements GUIComponent
{
	private static final ModelGui LABEL = Models.UI_LABEL;
	
	private Vec2d pos = new Vec2d(0, 0);
	private GUIButtonModel buttonDelete;
	private GUIButtonModel buttonPlay;
	private String text;
	
	public GUISavesCard(String text, Vec2d pos)
	{
		this.pos = pos;
		this.text = text;
		
		buttonDelete = new GUIButtonModel(Models.UI_BUTTON_DELETE, Models.UI_BUTTON_DELETE_HOVER, button -> {
			onDeletePressed();
		});
		
		buttonPlay = new GUIButtonModel(Models.UI_BUTTON_PLAY, Models.UI_BUTTON_PLAY_HOVER, button -> {
			onPlayPressed();
		});
		
		buttonPlay.setPos(pos.add(new Vec2d(LABEL.getWidth()*10/256.0, LABEL.getHeight()*6/32.0)));
		buttonDelete.setPos(pos.add(new Vec2d(LABEL.getWidth()*226/256.0, LABEL.getHeight()*6/32.0)));
	}
	
	public void onPlayPressed() {
		
	}
	
	public void onDeletePressed() {
		
	}

	@Override
	public void render(Matrix4 matrix, Vec2d mousePos, boolean canHover)
	{
		Matrix4 label_matrix = Matrix4.multiply(Matrix4.translate(pos.x, pos.y, 0), matrix);
		
		LABEL.setModel(label_matrix);
		LABEL.render();
		
		Matrix4 text_matrix = label_matrix;
		text_matrix = Matrix4.multiply(text_matrix, Matrix4.translate(
				LABEL.getWidth() * 38 / 256.0,
				LABEL.getHeight() / 2 - 0.25, 0));
		text_matrix = Matrix4.multiply(Matrix4.scale(new Vec3d(0.5, 0.5, 0.5)), text_matrix);
		
		Text.render(text, text_matrix);
		
		buttonDelete.render(matrix, mousePos, canHover);
		buttonPlay.render(matrix, mousePos, canHover);
	}

	@Override
	public void update(Vec2d mousePos) {
		buttonDelete.update(mousePos);
		buttonPlay.update(mousePos);
	}

	@Override
	public boolean checkMouseHover(Vec2d pos) {
		return true;
	}

	@Override
	public void onRightClick(Vec2d pos) {
		if(buttonDelete.checkMouseHover(pos))
			buttonDelete.onRightClick(pos);
		if(buttonPlay.checkMouseHover(pos))
			buttonPlay.onRightClick(pos);
	}

	@Override
	public void onMouseClick(Vec2d pos) {
		if(buttonDelete.checkMouseHover(pos))
			buttonDelete.onMouseClick(pos);
		if(buttonPlay.checkMouseHover(pos))
			buttonPlay.onMouseClick(pos);
	}

	@Override
	public void onActivate() {
		buttonDelete.onActivate();
		buttonPlay.onActivate();
	}

	@Override
	public void onBack() {
		buttonDelete.onBack();
		buttonPlay.onBack();
	}

	@Override
	public void onScroll(Vec2d mousePos, double amount) {
	}
	
}
