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

public class InventorySlot : MonoBehaviour {

	public Item currItem;
	public TextMeshPro countLabel;
	public Image icon;
    public GameObject DescriptionPanel;

	public UiDraggableItem dragItem;

	public void Sync(Item item)
	{
        DescriptionPanel.SetActive(false);
		icon.transform.gameObject.SetActive(true);
		countLabel.text = "";
		currItem = item;
		icon.sprite = item.InventoryGraphic;

        DescriptionPanel.transform.Find("Layout/Description").GetComponent<TextMeshPro>().text = item.Description;
        DescriptionPanel.transform.Find("Layout/Hunger").GetComponent<TextMeshPro>().text = "<b>Hunger:</b> " + item.HungerModifier.ToString();
        DescriptionPanel.transform.Find("Layout/Thirst").GetComponent<TextMeshPro>().text = "<b>Thirst:</b> " + item.ThirstModifier.ToString();
        DescriptionPanel.transform.Find("Layout/Confort").GetComponent<TextMeshPro>().text = "<b>Confort:</b> " + item.ConfortModifier.ToString();
        transform.gameObject.GetComponent<BoxCollider>().enabled = true;

		//if (item.MustBePlaced)
		//{
		transform.gameObject.GetComponent<BoxCollider>().enabled = true;
		transform.gameObject.GetComponent<UiDraggableItem>().enabled = true;
			dragItem.prefab = item.Prefab;
			dragItem.currItem = item;
			dragItem.placable = item.MustBePlaced;
		//}
	}

	public void Sync()
	{
        DescriptionPanel.SetActive(false);
        icon.transform.gameObject.SetActive(false);
		countLabel.text = "";
		transform.gameObject.GetComponent<BoxCollider>().enabled = false;
        transform.gameObject.GetComponent<UiDraggableItem>().enabled = false;

        DescriptionPanel.transform.Find("Layout/Description").GetComponent<TextMeshPro>().text = "";
        DescriptionPanel.transform.Find("Layout/Hunger").GetComponent<TextMeshPro>().text = "";
        DescriptionPanel.transform.Find("Layout/Thirst").GetComponent<TextMeshPro>().text = "";
        DescriptionPanel.transform.Find("Layout/Confort").GetComponent<TextMeshPro>().text = "";
    }
	// Use this for initialization
	void Start () {
		
	}
	
	// Update is called once per frame
	void Update () {
		
	}

    private void OnMouseDown()
    {
        DescriptionPanel.SetActive(true);
    }

    private void OnMouseExit()
    {
        DescriptionPanel.SetActive(false);
    }
}
