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

public class PlayerSelectionManager : MonoBehaviour
{
    public GameObject[] Elements;

    private Players Player1 = Players.NONE;
    private Players Player2 = Players.NONE;

    public void SelectCharacter(int number)
    {
        Debug.Log("Selected player " + (Players)number + " for player " + (Player1 == Players.NONE ? "one" : "two"));

        if (Player1 == Players.NONE)
            Player1 = (Players)number;
        else
            Player2 = (Players)number;
    }

    public void UpdateSelectedItem(EventSystem eventSystem)
    {
        if (Player2 == Players.NONE)
        {
            switch (Player1)
            {
                case Players.FAT:
                    eventSystem.SetSelectedGameObject(Elements[1]);
                    break;
                case Players.GIRL:
                    eventSystem.SetSelectedGameObject(Elements[2]);
                    break;
                case Players.BOY:
                    eventSystem.SetSelectedGameObject(Elements[0]);
                    break;
            }
        }
        else
        {
            PlayerPrefs.SetInt("Player1", (int)Player1);
            PlayerPrefs.SetInt("Player2", (int)Player2);

            SceneManager.LoadScene("Gameplay");
        }
    }

    private enum Players
    {
        NONE = 3,
        FAT = 0,
        GIRL = 1,
        BOY = 2
    }
}
