package openmods.gui.component.page;

import net.minecraft.client.Minecraft;
import net.minecraft.item.ItemStack;
import net.minecraft.util.IIcon;
import net.minecraft.util.StatCollector;
import openmods.gui.component.*;
import openmods.utils.RecipeUtils;
import openmods.utils.render.FakeIcon;

public class StandardRecipePage extends PageBase {

	public static IIcon iconCraftingGrid = FakeIcon.createSheetIcon(0, 180, 56, 56);
	public static IIcon iconArrow = FakeIcon.createSheetIcon(60, 198, 48, 15);

	private GuiComponentCraftingGrid craftingGrid;
	private GuiComponentSprite arrow;
	private GuiComponentLabel lblDescription;
	private GuiComponentLabel lblTitle;
	private GuiComponentItemStackSpinner outputSpinner;

	public StandardRecipePage(String title, String description, ItemStack resultingItem) {
		String translatedTitle = StatCollector.translateToLocal(title);
		String translatedDescription = StatCollector.translateToLocal(description).replaceAll("\\\\n", "\n");

		lblTitle = new GuiComponentLabel((getWidth() - Minecraft.getMinecraft().fontRenderer.getStringWidth(translatedTitle)) / 2, 12, translatedTitle);
		lblDescription = new GuiComponentLabel(27, 95, 340, 51, translatedDescription);
		arrow = new GuiComponentSprite(90, 50, iconArrow, BOOK_TEXTURE);
		craftingGrid = new GuiComponentCraftingGrid(25, 30, RecipeUtils.getFirstRecipeForItem(resultingItem), iconCraftingGrid, BOOK_TEXTURE);

		lblDescription.setScale(0.5f);
		lblDescription.setAdditionalLineHeight(4);

		outputSpinner = new GuiComponentItemStackSpinner(150, 40, resultingItem);

		addComponent(lblDescription);
		addComponent(lblTitle);
		addComponent(arrow);
		addComponent(outputSpinner);
		addComponent(craftingGrid);

	}

	public StandardRecipePage(String title, String description, String videoLink, ItemStack resultingItem) {
		this(title, description, resultingItem);
		String translatedLink = StatCollector.translateToLocal(videoLink);

		if (videoLink != "" && !videoLink.equals(translatedLink)) {
			addActionButton(25, 146, translatedLink, ActionIcon.YOUTUBE.icon, "openblocks.gui.watch_video");
		}
	}

}

@@ -506,294 +506,310 @@
 %0A%0A%09p
-rivate GuiComponentCraftingGrid craftingGrid;%0A%09private GuiComponentSprite arrow;%0A%09private GuiComponentLabel lblDescription;%0A%09private GuiComponentLabel lblTitle;%0A%09private GuiComponentItemStackSpinner outputSpinner;%0A%0A%09public StandardRecipePage(String title, String description, ItemStack 
+ublic StandardRecipePage(String title, String description, ItemStack resultingItem) %7B%0A%09%09addComponent(new GuiComponentSprite(90, 50, iconArrow, BOOK_TEXTURE));%0A%09%09addComponent(new GuiComponentItemStackSpinner(150, 40, resultingItem));%0A%0A%09%09%7B%0A%09%09%09final ItemStack%5B%5D recipe = RecipeUtils.getFirstRecipeForItem(
 resu
@@ -822,77 +822,135 @@
 tem)
- %7B%0A%09%09String translatedTitl
+;%0A%09%09%09if (recip
 e 
+!
 = 
-StatCollector.translateToLocal(title);%0A
+null) addComponent(new GuiComponentCraftingGrid(25, 30, recipe, iconCraftingGrid, BOOK_TEXTURE));%0A%09%09%7D%0A%0A%09%09%7B%0A%09
 %09%09St
@@ -964,27 +964,21 @@
 anslated
-Description
+Title
  = StatC
@@ -1007,62 +1007,32 @@
 cal(
-description).replaceAll(%22%5C%5C%5C%5Cn%22, %22%5Cn%22);%0A%0A%09%09lblTitle = 
+title);%0A%09%09%09addComponent(
 new 
@@ -1163,173 +1163,160 @@
 tle)
+)
 ;%0A%09%09
-lblDescription = new GuiComponentLabel(27, 95, 340, 51, translatedDescription);%0A%09%09arrow = new GuiComponentSprite(90, 50, iconArrow, BOOK_TEXTURE);%0A%09%09craftingGrid
+%7D%0A%0A%09%09%7B%0A%09%09%09String translatedDescription = StatCollector.translateToLocal(description).replaceAll(%22%5C%5C%5C%5Cn%22, %22%5Cn%22);%0A%09%09%09GuiComponentLabel lblDescription
  = n
@@ -1334,113 +1334,56 @@
 nent
-CraftingGrid(2
+Label(27, 9
 5, 3
+4
 0, 
-RecipeUtils.getFirstRecipeForItem(resultingItem), iconCraftingGrid, BOOK_TEXTURE);%0A%0A
+51, translatedDescription);%0A%09
 %09%09lb
@@ -1411,16 +1411,17 @@
 (0.5f);%0A
+%09
 %09%09lblDes
@@ -1461,228 +1461,44 @@
 4);%0A
-%0A
 %09%09
-outputSpinner = new GuiComponentItemStackSpinner(150, 40, resultingItem);%0A%0A%09%09addComponent(lblDescription);%0A%09%09addComponent(lblTitle);%0A%09%09addComponent(arrow);%0A%09%09addComponent(outputSpinner);%0A%09%09addComponent(craftingGrid);%0A
+%09addComponent(lblDescription);%0A%09%09%7D
 %0A%09%7D%0A

Fix infobook crash when no recipe available