package hud.constructionmenu;

import java.awt.Color;
import java.awt.Graphics2D;

import javax.swing.JOptionPane;

import _texture.loader.Textures;
import engine.MouseInput;
import fonts.fonts;
import hud.inventory.Inventory;
import utils.Utils;

/*  ------------- Nihilne ------------
    * Created by Mitch Weaver - 2016 *
      ~~~~ All Rights Reserved ~~~~ */

public final class ConstructionMenuHover {

	public static final String[] lines = Utils.makeStringArrayFromLinesOfTextFile("/itemTextsCapitalized.nihil");
	
	public static ConstructionItem item;
	public static boolean render;
	
	public static final void render(final Graphics2D g2d){
		if(!render) return;
		
		g2d.setColor(Color.gray);
		g2d.fillRect(MouseInput.mouseXY.x, MouseInput.mouseXY.y, 150, 150);
		
		g2d.setColor(Color.darkGray);
		g2d.fillRect(MouseInput.mouseXY.x + 5, MouseInput.mouseXY.y + 5, 140, 140);
		
		g2d.setColor(Color.black);
		g2d.fillRect(MouseInput.mouseXY.x + 11, MouseInput.mouseXY.y + 32, 70, 70);
		
		g2d.setColor(Color.lightGray);
		g2d.fillRect(MouseInput.mouseXY.x + 13, MouseInput.mouseXY.y + 34, 65, 65);
		
		try{ g2d.drawImage(Utils.reverseImage(Textures.itemIconSheet[item.itemId - 1]).getScaledInstance(80, 65, 1), MouseInput.mouseXY.x + 5, MouseInput.mouseXY.y + 33, null);
		} catch (Exception e){ secondaryRender(g2d); }
		
		g2d.setFont(fonts.Gregorian20);
		g2d.setColor(Color.white);
		
		g2d.drawString(lines[item.itemId - 1], MouseInput.mouseXY.x + 8, MouseInput.mouseXY.y + 23);
		
		flavorText(g2d);
		reqMaterials(g2d);
	}
	
	private static final void reqMaterials(final Graphics2D g2d){
		switch(item.price.length){ /* get the number of different items req */
			case 1: {
				g2d.setColor(Color.lightGray);
				g2d.fillRect(MouseInput.mouseXY.x + 57, MouseInput.mouseXY.y + 108, 32, 32);
				g2d.setColor(Color.black);
				g2d.fillRect(MouseInput.mouseXY.x + 59, MouseInput.mouseXY.y + 110, 28, 28);
				
				g2d.drawImage(Textures.itemIconSheet[item.price[0].itemId - 1].getScaledInstance(32, 32, 3), MouseInput.mouseXY.x + 57, MouseInput.mouseXY.y + 107, null);
				
				g2d.setFont(fonts.Gregorian20);
				
				if(Inventory.contains(item.price[0].itemId, item.price[0].quantity))
				g2d.setColor(Color.white); else g2d.setColor(Color.red);
				g2d.drawString("x" + item.price[0].quantity+"", MouseInput.mouseXY.x + 30, MouseInput.mouseXY.y + 136);
				break;
			}
			
			case 2: {
				g2d.setColor(Color.lightGray);
				g2d.fillRect(MouseInput.mouseXY.x + 15, MouseInput.mouseXY.y + 108, 32, 32);
				g2d.fillRect(MouseInput.mouseXY.x + 57, MouseInput.mouseXY.y + 108, 32, 32);
				g2d.setColor(Color.black);
				g2d.fillRect(MouseInput.mouseXY.x + 17, MouseInput.mouseXY.y + 110, 28, 28);
				g2d.fillRect(MouseInput.mouseXY.x + 59, MouseInput.mouseXY.y + 110, 28, 28);
				
				g2d.drawImage(Textures.itemIconSheet[item.price[0].itemId - 1].getScaledInstance(32, 32, 3), MouseInput.mouseXY.x + 15, MouseInput.mouseXY.y + 107, null);
				g2d.drawImage(Textures.itemIconSheet[item.price[1].itemId - 1].getScaledInstance(32, 32, 3), MouseInput.mouseXY.x + 57, MouseInput.mouseXY.y + 107, null);
				
				g2d.setFont(fonts.Gregorian20);
				
				if(Inventory.contains(item.price[0].itemId, item.price[0].quantity))
				g2d.setColor(Color.white); else g2d.setColor(Color.red);
				g2d.drawString("x" + item.price[0].quantity+"", MouseInput.mouseXY.x + 30, MouseInput.mouseXY.y + 136);
				if(Inventory.contains(item.price[1].itemId, item.price[1].quantity))
				g2d.setColor(Color.white); else g2d.setColor(Color.red);
				g2d.drawString("x" + item.price[1].quantity+"", MouseInput.mouseXY.x + 72, MouseInput.mouseXY.y + 136);
				break;
			}
			
			case 3: {
				g2d.setColor(Color.lightGray);
				g2d.fillRect(MouseInput.mouseXY.x + 15, MouseInput.mouseXY.y + 108, 32, 32);
				g2d.fillRect(MouseInput.mouseXY.x + 57, MouseInput.mouseXY.y + 108, 32, 32);
				g2d.fillRect(MouseInput.mouseXY.x + 100, MouseInput.mouseXY.y + 108, 32, 32);
				g2d.setColor(Color.black);
				g2d.fillRect(MouseInput.mouseXY.x + 17, MouseInput.mouseXY.y + 110, 28, 28);
				g2d.fillRect(MouseInput.mouseXY.x + 59, MouseInput.mouseXY.y + 110, 28, 28);
				g2d.fillRect(MouseInput.mouseXY.x + 102, MouseInput.mouseXY.y + 110, 28, 28);
				
				g2d.drawImage(Textures.itemIconSheet[item.price[0].itemId - 1].getScaledInstance(32, 32, 3), MouseInput.mouseXY.x + 15, MouseInput.mouseXY.y + 107, null);
				g2d.drawImage(Textures.itemIconSheet[item.price[1].itemId - 1].getScaledInstance(32, 32, 3), MouseInput.mouseXY.x + 57, MouseInput.mouseXY.y + 107, null);
				g2d.drawImage(Textures.itemIconSheet[item.price[2].itemId - 1].getScaledInstance(32, 32, 3), MouseInput.mouseXY.x + 100, MouseInput.mouseXY.y + 107, null);
				
				g2d.setFont(fonts.Gregorian20);
				
				if(Inventory.contains(item.price[0].itemId, item.price[0].quantity))
				g2d.setColor(Color.white); else g2d.setColor(Color.red);
				g2d.drawString("x" + item.price[0].quantity+"", MouseInput.mouseXY.x + 30, MouseInput.mouseXY.y + 136);
				if(Inventory.contains(item.price[1].itemId, item.price[1].quantity))
				g2d.setColor(Color.white); else g2d.setColor(Color.red);
				g2d.drawString("x" + item.price[1].quantity+"", MouseInput.mouseXY.x + 72, MouseInput.mouseXY.y + 136);
				if(Inventory.contains(item.price[2].itemId, item.price[2].quantity))
				g2d.setColor(Color.white); else g2d.setColor(Color.red);
				g2d.drawString("x" + item.price[2].quantity+"", MouseInput.mouseXY.x + 115, MouseInput.mouseXY.y + 136);
				break;
			}
			
			case 4: {
				g2d.setColor(Color.blue);
				g2d.fillRect(MouseInput.mouseXY.x, MouseInput.mouseXY.y, 100, 100);
				break;
			}
			default: { JOptionPane.showMessageDialog(null, "There is a problem with this item."); }
		}
	}
	
	private static final int X = 83, row1 = 75, row2 = 85, row3 = 95;
	private static final void flavorText(final Graphics2D g2d){
		g2d.setColor(Color.white);
		g2d.setFont(fonts.ponderosa8);
		
		switch(item.itemId){
			case 3: {
				g2d.drawString("It chops", MouseInput.mouseXY.x + X, MouseInput.mouseXY.y + row1);
				g2d.drawString("things.", MouseInput.mouseXY.x + X, MouseInput.mouseXY.y + row2);
				g2d.drawString("... kinda", MouseInput.mouseXY.x + 82, MouseInput.mouseXY.y + row3); break;
			}
			case 5: {
				g2d.drawString("Break", MouseInput.mouseXY.x + 82, MouseInput.mouseXY.y + row1);
				g2d.drawString("rock with", MouseInput.mouseXY.x + 82, MouseInput.mouseXY.y + row2);
				g2d.drawString("rock.", MouseInput.mouseXY.x + 82, MouseInput.mouseXY.y + row3); break;
			}
			case 8: {
				g2d.drawString("Nice,", MouseInput.mouseXY.x + 82, MouseInput.mouseXY.y + row1);
				g2d.drawString("safe, ", MouseInput.mouseXY.x + 82, MouseInput.mouseXY.y + row2);
				g2d.drawString("and warm.", MouseInput.mouseXY.x + 82, MouseInput.mouseXY.y + row3); break;
			}
			case 10: {
				g2d.drawString("For", MouseInput.mouseXY.x + 82, MouseInput.mouseXY.y + row1);
				g2d.drawString("burning", MouseInput.mouseXY.x + 82, MouseInput.mouseXY.y + row2);
				g2d.drawString("things.", MouseInput.mouseXY.x + 82, MouseInput.mouseXY.y + row3);
			}
		}
	}
	
	private static final void secondaryRender(final Graphics2D g2d){
		switch(item.itemId){
			case 8: g2d.drawImage(Utils.reverseImage(Textures.baseConstructionSheet[6]).getScaledInstance(80, 65, 1), MouseInput.mouseXY.x + 7, MouseInput.mouseXY.y + 35, null);
		}
	}
}
