using Intrepid.Utilities;
using TMPro;
using UnityEngine;
using UnityEngine.UI;

namespace Intrepid.Gameplay.Entities.Player.Sentinel.Cadence.UI
{
    public class UICadence : MonoBehaviour
    {
        [GroupInjections, SerializeField] private SentinelControls controls;
        [GroupInjections, SerializeField] private PlayerInputResolver inputResolver;
        [GroupInjections, SerializeField] private TextMeshProUGUI cadenceTimer;
        [GroupInjections, SerializeField] private TextMeshProUGUI btnElapsedTimes;
        [GroupInjections, SerializeField] private Slider effective;
        [GroupInjections, SerializeField] private Slider projection;

        private string _lastCadenceTimer;
        private string _lastCadenceConnectedCounter;
        
        private void Update()
        {
            if (CadenceService.Instance.IsCadenceRunning)
            {
                _lastCadenceTimer = $"{CadenceService.Instance.TotalCadenceElapsedTime * 1000f:F2}ms";
                _lastCadenceConnectedCounter = $"{controls.CadenceConnectedCounter}";
            }
            cadenceTimer.text = _lastCadenceTimer;
            btnElapsedTimes.text = _lastCadenceConnectedCounter;
            effective.value = CoreStabilityService.Instance.EffectiveStabilityP;
            projection.value = CoreStabilityService.Instance.ProjectedStabilityP;
        }
    }
}