using System.Collections.Generic;
using System.Linq;
using UnityEngine;

public class ShopStockView : MonoBehaviour
{
    [SerializeField] private SpriteRenderer popcornImage;
    [SerializeField] private float maxPosision = 0.16f;
    [SerializeField] private float minPosision = -0.8f;
    [SerializeField] private GameObject textObject;

    private void Awake()
    {
        textObject.SetActive(false);
    }

    public void SetStock(List<StorageTank> tanks)
    {
        var totalCapacity = tanks.Sum(x => x.Capacity);
        var totalStock = tanks.Sum(x => x.Stock);
        var newPos = popcornImage.transform.localPosition;
        newPos.y = Mathf.Lerp(minPosision, maxPosision, (float) totalStock / totalCapacity);
        popcornImage.transform.localPosition = newPos;
    }

    public void SetTextActive(bool active)
    {
        textObject.SetActive(active);
    }
}
