using UnityEngine;
using TMPro;
using Colyseus.Schema;

public class OnlineCounter : MonoBehaviour
{
    [SerializeField] private TextMeshProUGUI counterText;

    private void Update()
    {
        if (counterText == null) return;

        if (ArcadeNetworkManager.Instance == null || !ArcadeNetworkManager.Instance.IsConnected)
        {
            counterText.text = "Connecting...";
            return;
        }

        var room = ArcadeNetworkManager.Instance.Room;
        if (room != null && room.State != null && room.State.players != null)
        {
            int count = room.State.players.Count;
            counterText.text = count == 1 ? "1 visitor online" : $"{count} visitors online";
        }
    }
}
