﻿using UnityEngine;
using UnityEngine.UI;

public class StatisticBar : MonoBehaviour
{
	public StatisticType statisticType = null;
	public Slider slider = null;
	public Text label = null;

    private void OnEnable()
    {
        DogStatisticsHandler.OnStatisticChanged += UpdateSlider;
    }

    private void OnDisable()
    {
        DogStatisticsHandler.OnStatisticChanged -= UpdateSlider;
    }

    private void UpdateSlider(Statistic statistic)
    {
        if (statisticType == null || statistic.type != statisticType)
        {
            return;
        }

        label.text = statistic.name;
        slider.minValue = statistic.min;
        slider.maxValue = statistic.max;
        slider.value = statistic.value;
    }
}
