using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class GameManager : MonoBehaviour
{

    public GameObject IntroText;
    public float IntroDuration;
    private float introTimer;

    public PlayerController PlayerController;
    
    public GameObject ScoreBar;
    public Text ScoreText;
    private int score;
    public int Goal;

    public GameObject LoseText;
    public DeadState DeadState;

    public float PreLooseDuration;
    private float preLooseTimer;
    
    private bool hasLost;
    public float LooseDuration;
    private float looseTimer;
    
    public GameObject WinBar;
    public float WinDuration;
    private float winTimer;

    public GameObject Eaters;

    public GameObject HealthBar;

    

    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        if(Input.GetKeyDown(KeyCode.Escape))
            Application.Quit();

        introTimer += Time.deltaTime;
        if(IntroText.activeSelf && introTimer > IntroDuration)
        {
            IntroText.SetActive(false);
            ScoreBar.SetActive(true);
            PlayerController.enabled = true;
            Eaters.SetActive(true);
            HealthBar.SetActive(true);
        }
            

        if(DeadState.enabled) 
        {
            preLooseTimer += Time.deltaTime;
            if(preLooseTimer > PreLooseDuration)
                hasLost = true;
        }

        if(hasLost)
        {
            if(LoseText.activeSelf == false)
            {
                LoseText.SetActive(true);
                HealthBar.SetActive(false);
                ScoreBar.SetActive(false);
            }
                

            looseTimer += Time.deltaTime;
            if(looseTimer > LooseDuration)
            {
                //end
            }
        }

        if(WinBar.activeSelf)
        {
            winTimer += Time.deltaTime;
            if(winTimer > WinDuration)
            {
                //end
            }
        }

        
        
    }

    public void IncreaseScore()
    {
        score ++;
        ScoreText.text = score.ToString();

        if(score >= Goal)
        {
            WinBar.SetActive(true);
            ScoreBar.SetActive(false);
            Eaters.SetActive(false);
            HealthBar.SetActive(false);
        }
    }
}
