using DoomDeathmatch.Component.MVC.View;
using Engine.Util;

namespace DoomDeathmatch.Component.MVC.Controller;

public class TimerController : Engine.Scene.Component.Component
{
  public bool IsPaused { get; set; } = false;
  public event Action? OnFinished;

  private readonly TickableTimer _tickableTimer = new(60 + 10);
  private TimerView _timerView = null!;

  public override void Awake()
  {
    _timerView = GameObject.GetComponent<TimerView>()!;
    _timerView.UpdateView(_tickableTimer.CurrentTime);

    _tickableTimer.OnUpdate += OnTimeChanged;
    _tickableTimer.OnFinished += OnFinished;
  }

  public override void Update(double parDeltaTime)
  {
    if (IsPaused)
      return;

    _tickableTimer.Update(parDeltaTime);
  }

  private void OnTimeChanged(double parTime)
  {
    _timerView.UpdateView(parTime);
  }
}