using DG.Tweening;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;

public class Finale : MonoBehaviour
{
    public Transform scoreBoard;
    public Transform sightLine;
    public GameObject buttonGroup;

    public Transform fakePlayer;

    private bool launched = false;

    private void GrowScoreBoard()
    {
        scoreBoard.DOScale(3, 1.8f).SetEase(Ease.InQuad);
        scoreBoard.DOMove(Vector3.zero, 1f);
    }

    private void RemoveDarkness()
    {
        sightLine.DOScale(8f, 5f);
    }

    private void SetFakePlayer()
    {
        Player.playerTransform = fakePlayer;
    }

    private void ShowButtonGroup()
    {
        buttonGroup.SetActive(true);
    }

    private void Spin()
    {
        transform.eulerAngles += new Vector3(0, 0, 20 * Time.deltaTime);
    }

    private void Update()
    {
        // if (Input.GetKeyDown(KeyCode.Alpha9))
        // {
        //     Score.ScoreCash();
        // }

        if(!Score.GameFinished())
        {
            return;
        }

        if(!launched)
        {
            launched = true;
            Invoke("GrowScoreBoard", 0.5f);
            Invoke("RemoveDarkness", 0f);
            Invoke("SetFakePlayer", 2f);
            Invoke("ShowButtonGroup", 3f);
        }

        Spin();
    }

    public void OnClickReplay()
    {
        DOTween.KillAll();
		SceneManager.LoadScene(SceneManager.GetActiveScene().name);
    }

    public void OnClickQuit()
    {
        Application.Quit();
    }
}

