using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Networking.Client;

public class LobbyWaitManager : MonoBehaviour
{
    [SerializeField]
    private ConnectedClients AllClients;
    [SerializeField]
    private ClientObject localClient;

    [SerializeField]
    private UnityEngine.UI.Button StartButton;

    private void OnEnable()
    {
        AllClients.OnClientsChange += UpdateButton;
    }

    private void OnDisable()
    {
        AllClients.OnClientsChange -= UpdateButton;
    }

    private void Start()
    {
        UpdateButton(AllClients.AllClients);
    }

    public void OnClick_Start()
    {
        localClient.client.Send(LoginProtocols.StartGame, new Networking.LogicProtocols.EmptyMsg());
    }

    private void UpdateButton(List<ClientData> AllClients)
    {
        if (AllClients.Count > 0 && AllClients[0].characterAnimal == localClient.PlayerAnimal)
        {
            StartButton.gameObject.SetActive(true);
        }
        else
        {
            StartButton.gameObject.SetActive(false);
        }
    }

}
