using UnityEngine;
using UnityEngine.UI;
using System.Collections;

public class InventoryManager : MonoBehaviour {
	
	public Animator anim;
	public Text pickUpObject;
	public static string activeItem = null;

	public int bloodCount, hornCount, hairCount, weedCount, stickCount, diamondCount, saphireCount, topazCount, emeraldCount, rubyCount = 0;
	public GameObject bloodObject, hornObject, hairObject, weedObject, stickObject, diamondObject, saphireObject, topazObject, emeraldObject, rubyObject;

	public Text ruby;
	public Text saphire;
	public Text emerald;
	public Text topaz;
	public Text diamond;
	public Text stick;
	public Text weed;
	public Text hair;
	public Text horn;
	public Text blood;


	// Use this for initialization
	void Start () {
		
	}
	
	// Update is called once per frame
	void Update () {
		
	}


	void OnCollisionEnter(Collision coll){
		if (coll.gameObject.tag == "PowerUp") {
			anim.SetTrigger ("Pick");
			pickUpObject.text = (coll.gameObject.name);
			//StartCoroutine (itemPick (coll.gameObject.name));
			switch (coll.gameObject.name) {
			case "Ruby":
				rubyCount += 1;
				break;
			case "Emerald":
				emeraldCount += 1;
				break;
			case "Topaz":
				topazCount += 1;
				break;
			case "Saphire":
				saphireCount += 1;
				break;
			case "Diamond":
				diamondCount += 1;
				break;
			case "Stick":
				stickCount += 1;
				break;
			case "Weed"://420 blaze it
				weedCount +=1; //smoke weed everyday
				break;//fegget
			case "Hair":
				hairCount += 1;
				break;
			case "Horn":
				hornCount += 1;
				break;
			case "Blood":
				bloodCount += 1;
				break;
			}
			editUI (coll.gameObject.name);
		//	Debug.Log (coll.gameObject.name);
			Destroy (coll.gameObject);
		}

	}
	public bool useItem(string type)
	{
		switch (type) {
		case "Ruby":
			if (rubyCount > 0) {
				rubyCount -= 1;
			} else {
				return false;
			}
			break;
		case "Emerald":
			if (emeraldCount > 0) {
				emeraldCount -= 1;
			} else {
				return false;
			}
			break;
		case "Topaz":
			if (topazCount > 0) {
				topazCount -= 1;
			} else {
				return false;
			}
			break;
		case "Saphire":
			if (saphireCount > 0) {
				saphireCount -= 1;
			} else {
				return false;
			}
			break;
		case "Diamond":
			if (diamondCount > 0) {
				diamondCount -= 1;
			} else {
				return false;
			}
			break;
		case "Stick":
			if (stickCount > 0) {
				stickCount -= 1;
			} else {
				return false;
			}
			break;
		case "Weed"://420 blaze it
			if (weedCount > 0) {
				weedCount -= 1;
			} else {
				return false;
			} //smoke weed everyday
			break;//fegget
		case "Hair":
			if (hairCount > 0) {
				hairCount -= 1;
			} else {
				return false;
			}
			break;
		case "Horn":
			if (hornCount > 0) {
				hornCount -= 1;
			} else {
				return false;
			}
			break;
		case "Blood":
			if (bloodCount > 0) {
				bloodCount -= 1;
			} else {
				return false;
			}
			break;
		}
		editUI (type);
		return true;
	}
	int getItemCount(string type){
		
		switch (type) {
		case "Ruby":
			return rubyCount;
			break;
		case "Emerald":
			return emeraldCount;
			break;
		case "Topaz":
			return topazCount;
			break;
		case "Saphire":
			return saphireCount;
			break;
		case "Diamond":
			return diamondCount;
			break;
		case "Stick":
			return stickCount;
			break;
		case "Weed"://420 blaze it
			return weedCount +=1; //smoke weed everyday
			break;//fegget
		case "Hair":
			return hairCount;
			break;
		case "Horn":
			return hornCount;
			break;
		case "Blood":
			return bloodCount;
			break;
		}
		return 0;
	}

	void editUI(string type) {
		Text local = null;
		switch (type) {
		case "Ruby":
			local =ruby;
			break;
		case "Emerald":
			local =emerald;
			break;
		case "Topaz":
			local =topaz;
			break;
		case "Saphire":
			local =saphire;
			break;
		case "Diamond":
			local =diamond;
			break;
		case "Stick":
			local =stick;
			break;
		case "Weed"://420 blaze it
			local =weed; //smoke weed everyday
			break;//fegget
		case "Hair":
			local =hair;
			break;
		case "Horn":
			local =horn;
			break;
		case "Blood":
			local =blood;
			break;
		}
		print (type);
		local.text = getItemCount (type).ToString();
	}

	public void activateItem(string type ) {
//		bloodObject.GetComponent<ItemSlot>().setActive(("Blood".Equals(type))? true : false);
//		hornObject.GetComponent<ItemSlot>().setActive(("Horn".Equals(type))? true : false);
//		hairObject.GetComponent<ItemSlot>().setActive(("Hair".Equals(type))? true : false);
//		weedObject.GetComponent<ItemSlot>().setActive(("Weed".Equals(type))? true : false);
//		stickObject.GetComponent<ItemSlot>().setActive(("Stick".Equals(type))? true : false);
		diamondObject.GetComponent<ItemSlot>().setActive(("Diamond".Equals(type))? true : false);
		saphireObject.GetComponent<ItemSlot>().setActive(("Saphire".Equals(type))? true : false);
		topazObject.GetComponent<ItemSlot>().setActive(("Topaz".Equals(type))? true : false);
		emeraldObject.GetComponent<ItemSlot>().setActive(("Emerald".Equals(type))? true : false);
		rubyObject.GetComponent<ItemSlot>().setActive(("Ruby".Equals(type))? true : false);
		activeItem = type;
	}
}
