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

public class Inventory : MonoBehaviour
{

    public GameObject InventoryInterface;

    public int CurrentItemID;

    [HideInInspector]
    public int[] ItemCounts;
    [HideInInspector]
    public bool[] ItemUnlocks;

    void Start()
    {
        ItemCounts = new int[Global.ITEM_COUNT];
        ItemUnlocks = new bool[Global.ITEM_COUNT];
        ItemUnlocks[Global.ITEM_WOOD] = true;
        ItemUnlocks[Global.ITEM_BEET] = true;
    }


    void Update()
    {
        for (var i = 0; i < Global.ITEM_COUNT; i++)
        {
            var iconObject = InventoryInterface.transform.Find($"Icon {Global.ItemNames[i]}");
            var textObject = iconObject.transform.Find($"Text Counter {Global.ItemNames[i]}");
            textObject.GetComponent<TextMeshProUGUI>().text = ItemCounts[i].ToString(CultureInfo.InvariantCulture);
            if (ItemCounts[i] > 0)
                ItemUnlocks[i] = true;
        }
    }

    public int GetCount(int itemID)
    {
        return ItemCounts[itemID];
    }

    public void Add(int itemID, int count)
    {
        ItemCounts[itemID] += count;
    }

    public void Remove(int itemID, int count)
    {
        ItemCounts[itemID] -= count;
    }

}
