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

public class InventorySlot : MonoBehaviour
{
    Image image;
    public Image selectionOutline;
    public Sprite hover, selected;
    public SpaceObject spaceObject;    

    private void Awake()
    {
        image = GetComponent<Image>();
        image.enabled = false;        
    }

    private void Start()
    {
        OnUnhover();
    }

    public void SetItem(SpaceObject spaceObject)
    {
        this.spaceObject = spaceObject;
        image.enabled = true;
        image.sprite = spaceObject.GetComponent<SpriteRenderer>().sprite;
    }    
    
    public void RemoveItem()
    {
        spaceObject = null;
        image.enabled = false;
        selectionOutline.enabled = false;
    }

    public bool IsOccupied()
    {
        if (spaceObject == null) return false;
        return true;
    }

    public void OnHover()
    {
        if (GameManager.instance.inventory.selectedSlot == this)
        {

        }
        else
        {
            selectionOutline.sprite = hover;
            selectionOutline.enabled = true;
        }
    }

    public void OnUnhover()
    {
        if (GameManager.instance.inventory.selectedSlot == this)
        {

        }
        else
        {
            selectionOutline.sprite = null;
            selectionOutline.enabled = false;
        }
    }

    public void OnClick()
    {
        selectionOutline.sprite = selected;
        selectionOutline.enabled = true;
        GameManager.instance.inventory.SetSelectedInventorySlot(this);

        foreach (InventorySlot slot in GameManager.instance.inventorySlots)
        {
            slot.OnUnhover();
        }
    }
}
