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

public class UIController : MonoBehaviour
{
    [SerializeField] private TMP_Text pointsTxt;

    [SerializeField] private HealthBar mainHealthBar;
    [SerializeField] private HealthBar[] verticalHealthBars;

    [SerializeField] private Color[] hpBarColorPerDimension;

    public void UpdatePointsText(float points)
    {
        pointsTxt.text = points.ToString("0");
    }

    public void SetCurrentDimension(int currentDimensionID, float currentDimensionHP, float currentDimensionMaxHP) 
    {
        foreach (HealthBar verticalHealthBar in verticalHealthBars) 
        {
            verticalHealthBar.SetVisible(true);
        }
        verticalHealthBars[currentDimensionID].SetVisible(false);

        mainHealthBar.SetFillingColor(hpBarColorPerDimension[currentDimensionID]);
        mainHealthBar.SetFillingAmount(currentDimensionHP / currentDimensionMaxHP);
    }

    public void SetDimensionHP(int currentDimensionID, int dimensionID, float hp, float maxHP) 
    {
        float hpFillingAmount = hp / maxHP;
        verticalHealthBars[dimensionID].SetFillingAmount(hpFillingAmount);

        // Also change main HP bar if this is the current dimension.
        if (currentDimensionID == dimensionID)
        {
            mainHealthBar.SetFillingAmount(hpFillingAmount);
        }
    }
}
