using HeathenEngineering;
using System.Collections;
using System.Collections.Generic;
using UDB.UI;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.Events;

public class NetworkPauseManager : MonoBehaviour
{
    [SerializeField]
    private MenuCoordinator menuCoordinator;
    [SerializeField]
    private BoolReference canPause;
    public BetterEvent OnPause;

    public UnityEvent OnPauseEvent;

    private void Update()
    {
        if (canPause.Value == false) {
            return;
        }
        if (InControl.InputManager.ActiveDevice.RightCommand.WasPressed || Input.GetKeyDown(KeyCode.Escape)) {
            if (menuCoordinator.hasActiveMenu == false) {
                OnPause.Invoke();
                OnPauseEvent.Invoke();
            }
        }
    }

    public void SetTimeScaleToZero() => SetTimeScale(0.0f);
    public void SetTimeScaleToOne() => SetTimeScale(1.0f);

    public void SetTimeScale(float timeScale)
    {
        if (NetworkManager.Singleton.IsServer) {
            Time.timeScale = timeScale;
        }
    }

    void OnValidate()
    {
        if(OnPause.Events.Count > 0) {
            Debug.LogWarning("REMOVE EVENTS FROM BETTER EVENT AND ADD THEM TO UNITY EVENT. BETTER EVENTS IS GETTING REMOVED 8/1/2023");
        }
    }
}
