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

public class ProcessScore : Process {

    // Use this for initialization

    public GameObject buttonMenu;
    public GameObject buttonNextLvl;
    public GameObject buttonRestart;
    public GameObject buttonNextScore;
    public GameObject buttonPrevScore;
    public int lvlhighScore;
   

    public Text textscore;


    public override void Init()
    {
       

        lvlhighScore = 1;

        buttonNextScore.SetActive(false);
        buttonPrevScore.SetActive(false);

        if (LoadLevel.instance.currentLevel == 3 || LoadLevel.instance.currentLevel == 0)
            buttonNextLvl.SetActive(false);
        else
            buttonNextLvl.SetActive(true);


        if (LoadLevel.instance.currentLevel == 0)
        {
            buttonRestart.SetActive(false);
            buttonNextScore.SetActive(true);

        }
        else
        {
            buttonRestart.SetActive(true);
        }


        

    }


    // Update is called once per frame
    void Update ()
    {
        
        if(lvlhighScore==3 && LoadLevel.instance.currentLevel == 0)
        {
            buttonNextScore.SetActive(false);
        }
        else
        { 
            if(LoadLevel.instance.currentLevel == 0)
            buttonNextScore.SetActive(true);
        }

        if(lvlhighScore==1 && LoadLevel.instance.currentLevel == 0)
        {
            buttonPrevScore.SetActive(false);
        }
        else
        {
            if(LoadLevel.instance.currentLevel ==0)
            buttonPrevScore.SetActive(true);
        }


        if (LoadLevel.instance.currentLevel == 0)
        {
            switch (lvlhighScore)
            {
                case 1:

                    textscore.text = "Niveau 1\n\n   Meilleur Score: " + Score.meilleurScoreLvl1.ToString("0") + "    \n\n   En " + Score.meilleurTpsLvl1 + " secondes!";
                    break;

                case 2:

                    textscore.text = "Niveau 2\n\n   Meilleur Score: " + Score.meilleurScoreLvl2.ToString("0") + "    \n\n   En " + Score.meilleurTpsLvl2 + " secondes!";
                    break;

                case 3:

                    textscore.text = "Niveau 3\n\n   Meilleur Score: " + Score.meilleurScoreLvl3.ToString("0") + "    \n\n   En " + Score.meilleurTpsLvl3 + " secondes!";
                    break;
            }
        }
        else
        {
            if (LoadLevel.instance.currentLevel == 1)
            {
                textscore.text = "Fin du niveau 1! \n\n   Vous totalisez un score de " + Score.scoreLvl1.ToString("0") + " en " + Score.tpsLvl1 + " secondes.\n\n\n Le meilleur Score étant de " + Score.meilleurScoreLvl1.ToString("0") + " en " + Score.meilleurTpsLvl1 + " secondes.";

            }

            if (LoadLevel.instance.currentLevel == 2)
            {
                textscore.text = "Fin du niveau 2! \n\n   Vous totalisez un score de " + Score.scoreLvl2.ToString("0") + " en " + Score.tpsLvl2 + " secondes.\n\n\n Le meilleur Score étant de " + Score.meilleurScoreLvl2.ToString("0") + " en " + Score.meilleurTpsLvl2 + " secondes.";
            }

            if (LoadLevel.instance.currentLevel == 3)
            {
                textscore.text = "Fin du niveau 3! \n\n   Vous totalisez un score de " + Score.scoreLvl3.ToString("0") + " en " + Score.tpsLvl3 + " secondes.\n\n\n Le meilleur Score étant de " + Score.meilleurScoreLvl3.ToString("0") + " en " + Score.meilleurTpsLvl3 + " secondes.";
            }
        }
    }



    

    public void OnClickNext()
    {
        LoadLevel.instance.LoadLvl(LoadLevel.instance.currentLevel + 1);
    }

    public void OnClickMenu()
    {
        Destroy(LoadLevel.instance.parent);
        Destroy(LoadLevel.instance.parentsub);

        if (LoadLevel.instance.currentLevel == 0)
            StateMachine.instance.SetState(STATE.MENU);
        else
            StateMachine.instance.SetState(STATE.SELECTLVL);
    }

    public void OnClickNextScore()
    {
        buttonPrevScore.SetActive(true);

        if(lvlhighScore==3)
        {

            
            lvlhighScore = 3;

        }
        else
        {
            lvlhighScore++;
        }
    }

    public void OnClickPrevScore()
    {
               
        if (lvlhighScore == 1)
        {
            lvlhighScore = 1;
        }
        else
        {
            lvlhighScore--;
        }


    }


}
