using UnityEngine;
using UnityEngine.UI;
using ScrambleKit.Hits;
using ScrambleKit.Game;

namespace ScrambleKit.UI
{
    public class PlayerHitPointsPip : MonoBehaviour
    {

        public int Number;
        public Sprite None;
        public Sprite Empty;
        public Sprite Full;

        private Image image;
        private HitPoints hp;

        void Start()
        {
            image = transform.GetComponent<Image>();

            if (GameInfo.Player == null)
            {
                Debug.LogError("ScrambleKit Error: PlayerHitPointsPip requires registered player GameObject.  Attach ScrambleKit.Game.RegisterAsPlayer to your Player GameObject.");
                return;
            }

            hp = GameInfo.Player.GetComponent<HitPoints>();
            if (hp == null)
                Debug.LogError("ScrambleKit Error: PlayerHitPointsPip requires the registered player GameObject to have a HitPoints component.");
        }

        void Update()
        {
            if (hp == null || image == null)
                return;

            if (hp.HP >= Number)
                image.sprite = Full;
            else if (hp.MaxHP >= Number)
                image.sprite = Empty;
            else
                image.sprite = None;
        }
    }
}