using System.Collections.Generic;
using Assets.Source.Content.UI.Dialogues;
using Assets.Source.Core.Gameplay.Topdown;
using UnityEngine.UI;
using UnityEngine;
using DG.Tweening;

namespace Assets.Source.Content.UI.Topdown
{
    public class UITopdownInventoryDialogue : UIBaseDialogue
    {
        [SerializeField] private GameObject fillIndicator;
        [SerializeField] private int itemsCountToDeactivate = 2;
        [SerializeField] private float transparencyRange = 0.2f;
        [SerializeField] private float blinkTime = 1;

        //public List<UIItemSlot> Images;
        public List<Image> ScenarioItems;

        public Image AlienCharacterImage;
        public Image ScenarioCharacterImage;
        public Image ScenarioItemImage;

        private PlayerInventory inventory;
        private Image imageIndicator;
        private Sequence colorSequence;

        private int currentSlot = 0;
        private float maxTransparency, minTransparency;

        void Start()
        {
            inventory = GameManagerTopdown.Instance.PlayerInventory;
            inventory.OnItemAdded += OnItemAdded;

            //SetActivateIndicator(true);
            imageIndicator = fillIndicator.GetComponentInChildren<Image>();

            maxTransparency = 1;
            minTransparency = maxTransparency - transparencyRange;
            //colorSequence = DOTween.Sequence();
            //StartSequence();
        }

        private void OnItemAdded(InventoryItem item)
        {
            //Images[currentSlot++].sprite = item.icon;
            if (currentSlot > itemsCountToDeactivate - 1)
            {
                //SetActivateIndicator(false);
            }
            else
            {
                //maxTransparency /= 2;//-= transparencyRange;
                //minTransparency /= 2;//-= transparencyRange;
                //StartSequence();
            }
        }

        private void SetActivateIndicator(bool _on)
        {
            fillIndicator.SetActive(_on);
        }

        private void StartSequence()
        {
            colorSequence.Pause();
            imageIndicator.color = new Color(1, 1, 1, maxTransparency);
            imageIndicator.DOColor(new Color(1, 1, 1, minTransparency), blinkTime).SetLoops(-1, LoopType.Yoyo);
            colorSequence.Restart();
        }

        void Update()
        {
            UpdateIndicator();
        }

        private void UpdateIndicator()
        {
            
        }
    }
}
