using System;
using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;

public class TimeManager : MonoBehaviour
{
    public TMP_Text dayCounter;
    public int elapsedDays;
    public float elapsedHours;
    public bool paused;
    public float gameSpeed;
    public float secondsPerDay;

    // Start is called before the first frame update
    void Start()
    {
        paused = false;
        gameSpeed = 24 / (secondsPerDay + 0.0001f);
    }

    // Update is called once per frame
    void Update()
    {
        dayCounter.text = ElapsedDays().ToString() + " : " + String.Format("{0,2:D2}", ElapsedHours());
        if (GameManager.Instance().Paused())
        {
            return;
        }

        var deltaHours = Time.deltaTime * gameSpeed;
        elapsedHours += deltaHours;
        GameManager.Instance().AdvanceTime(deltaHours);
        if (elapsedHours >= 24)
        {
            elapsedHours -= 24;
            elapsedDays += 1;
            GameManager.Instance().NextDay();
        }
    }

    public int ElapsedDays()
    {
        return elapsedDays;
    }

    public int ElapsedHours()
    {
        return (int)elapsedHours;
    }

    public bool Paused()
    {
        return paused;
    }
}
