﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class ItemUI : MonoBehaviour {

	public Image pickupBG, lootChestBG;
	public Text itemName, itemType, itemSubType, itemRarity;
	public GameObject displayObj, lootChestDisplay;


	void Update () 
	{

		if (displayObj) 
		{
			Vector3 _bgPos = Camera.main.WorldToScreenPoint (displayObj.transform.position) + new Vector3 (175f, 75f, 0f);
			pickupBG.transform.position = _bgPos;
			if (!pickupBG.gameObject.activeInHierarchy)
				pickupBG.gameObject.SetActive (true);
		} 
		else if (pickupBG.gameObject.activeInHierarchy) 
		{
			pickupBG.gameObject.SetActive (false);
		}

		if (lootChestDisplay)
		{
			Vector3 _bgPos = Camera.main.WorldToScreenPoint (lootChestDisplay.transform.position) + new Vector3 (175f, 75f, 0f);
			lootChestBG.transform.position = _bgPos;
			if (!lootChestBG.gameObject.activeInHierarchy)
				lootChestBG.gameObject.SetActive(true);
		}
		else if (lootChestBG.gameObject.activeInHierarchy)
		{
			lootChestBG.gameObject.SetActive(false);
		}
	}

	public void AssignUINewWand(NewWandScript script)
	{

		displayObj = script.Model.gameObject;
        string wandName = script.DisplayName == "" ? script.gameObject.name : script.DisplayName;
		itemName.text = (wandName.Contains("(")) ? itemName.text = wandName.Remove(wandName.IndexOf("(")) : itemName.text = wandName;
		wandName = itemName.text;
		itemName.text = (wandName.Contains("_")) ? itemName.text = wandName.Remove(wandName.IndexOf("_")) : itemName.text = wandName;
        
        itemType.text = "Type: " + script.SpellType.Primary.ToString();
		itemSubType.text = "Spell: " + script.SpellName.ToString();
		itemRarity.text = "Rarity: " + script.Rarity.ToString();
		pickupBG.color = script.IconColor;
	}

	public void AssignUIPotion (PotionScript script) {
		displayObj = script.gameObject;
		itemName.text = (script.gameObject.name.Contains ("(")) ? itemName.text = script.gameObject.name.Remove (script.gameObject.name.IndexOf ("(")) : itemName.text = script.gameObject.name;
		itemType.text = "Type: " + script.potion.type.ToString ();
		itemSubType.text = "Size: " + script.potion.size.ToString ();
		itemRarity.text = "Rarity: " + script.potion.potionRarity.ToString ();
		pickupBG.color = script.potion.iconColor;
	}
}
