package projectzombie.menu;

import gl_engine.matrix.Matrix4;
import gl_engine.vec.Vec2d;
import projectzombie.Main;
import projectzombie.init.Items;
import projectzombie.init.Models;
import projectzombie.init.Recipes;
import projectzombie.inventory.Crafting;
import projectzombie.inventory.Inventory;
import projectzombie.inventory.recipe.Recipe;
import projectzombie.menu.gui.GUIContainerSlider;
import projectzombie.menu.gui.GUIItemSlot;
import projectzombie.menu.gui.GUIItemSlotGetter;
import projectzombie.menu.gui.GUIRecipeCard;
import projectzombie.util.ItemStack;

public class MenuInventoryStorage extends MenuInventory
{
	private GUIContainerSlider slider;
	
	public MenuInventoryStorage(Menu parent, Inventory container)
	{
		this(parent, container, new GUIItemSlotGetter()
		{
			@Override
			public void setItemStack(ItemStack stack) {
			}
			
			@Override
			public boolean isAllowed(ItemStack stack) {
				return true;
			}
			
			@Override
			public ItemStack getItemStack() {
				return null;
			}
		});
	}

	public MenuInventoryStorage(Menu parent, Inventory container, GUIItemSlotGetter getter) {
		super(parent);
		
		double w = Models.UI_SELECTION_BOX_STORAGE.getWidth();
		double h = Models.UI_SELECTION_BOX_STORAGE.getHeight();
		
		slider = new GUIContainerSlider(new Vec2d(
				w * 28 / 256.0, -h / 2), new Vec2d(
				w * 192 / 256.0, h),
				Math.floor(container.getSlotCount() / 6 + 1.5) *
				1.5 - Models.UI_INVENTORY.getHeight());
		
		for(int i=0;i<container.getSlotCount();i++)
		{
			int[] index = {i};
			
			int col = i / 6;
			int row = i % 6;
			
			GUIItemSlot slot = new GUIItemSlot(1.5, true, new GUIItemSlotGetter() {
				
				@Override
				public void setItemStack(ItemStack stack) {
					container.setItem(stack, index[0]);
				}
				
				@Override
				public boolean isAllowed(ItemStack stack) {
					return getter.isAllowed(stack);
				}
				
				@Override
				public ItemStack getItemStack() {
					return container.getItem(index[0]);
				}
				
				@Override
				public boolean isReadOnly() {
					return getter.isReadOnly();
				}
				
				@Override
				public boolean mustTakeAll() {
					return getter.mustTakeAll();
				}
				
				@Override
				public void onRemoveItemStack() {
					getter.onRemoveItemStack();
				}
				
				@Override
				public boolean renderSlot() {
					return true;
				}
			});
			
			slot.setPos(new Vec2d(
					w * 28.0 / 256.0 + 0.325 + w * row * 32 / 256.0,
					-h * col * 32 / 256.0 - 1.175 + w / 2));
			
			slider.add(slot);
		}
		
		gui.add(slider);
	}
	
	/*
	@Override
	public void render()
	{
		Matrix4 matrix = Matrix4.translate(0, -Models.UI_INVENTORY.getHeight() / 2, 0);
		
		// Render the inventory gui
		Models.UI_SELECTION_BOX_STORAGE.setModel(matrix);
		Models.UI_SELECTION_BOX_STORAGE.render();
		
		super.render();
	}
	*/
}
