using UnityEngine;
using UnityEngine.UI;
using System.Collections;
using UnityEngine.SceneManagement;
using Assets.Scripts;
using Assets.Scripts.API;
using Assets.Scripts.Utils;

public class GameOver : MonoBehaviour
{
//    private float _timer = 0f;
	private int score = 0;

	private GameObject _player;
	public InputField PlayerName;
	public InputField TeamName;
	public Text Score;
	public Button buttonSubmit;
	public Button buttonPlay;

    void Start()
    {
    }
	
	void Update ()
	{
//	    _timer += Time.deltaTime;
//        if (_timer > 4f)
//            SceneManager.LoadScene("Menu");
		score = PlayerPrefs.GetInt("lastscore");
		Score.text = "You scored " + score;
		BackButtonHelper.playOnBack();
	}

	public void OnButtonPlayClicked()
	{
		SceneManager.LoadScene("Main");
	}

	public void OnButtonSubmitClicked()
	{
		string playerText = PlayerName.text;
		if (playerText == null || playerText.Length == 0) {
			playerText = "Random Randy";
		}
		string teamText = TeamName.text;
		if (teamText == null || teamText.Length == 0) {
			teamText = null;
		}
		Server.PostScore(score, playerText, teamText);
		buttonSubmit.enabled = false;
		SceneManager.LoadScene("Scores");
	}
}
